Skip to content

Commit 22486cc

Browse files
Add return types, round 1
1 parent 7c878ab commit 22486cc

File tree

3 files changed

+8
-75
lines changed

3 files changed

+8
-75
lines changed

Inline.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ public static function initialize(int $flags, int $parsedLineNumber = null, stri
5454
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
5555
* @param array $references Mapping of variable names to values
5656
*
57-
* @return mixed A PHP value
58-
*
5957
* @throws ParseException
6058
*/
61-
public static function parse(string $value = null, int $flags = 0, array &$references = [])
59+
public static function parse(string $value = null, int $flags = 0, array &$references = []): mixed
6260
{
6361
self::initialize($flags);
6462

@@ -112,8 +110,6 @@ public static function parse(string $value = null, int $flags = 0, array &$refer
112110
* @param mixed $value The PHP variable to convert
113111
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
114112
*
115-
* @return string The YAML string representing the PHP value
116-
*
117113
* @throws DumpException When trying to dump PHP resource
118114
*/
119115
public static function dump(mixed $value, int $flags = 0): string
@@ -213,8 +209,6 @@ public static function isHash(array|\ArrayObject|\stdClass $value): bool
213209
*
214210
* @param array $value The PHP array to dump
215211
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
216-
*
217-
* @return string The YAML string representing the PHP array
218212
*/
219213
private static function dumpArray(array $value, int $flags): string
220214
{
@@ -249,11 +243,9 @@ private static function dumpNull(int $flags): string
249243
/**
250244
* Parses a YAML scalar.
251245
*
252-
* @return mixed
253-
*
254246
* @throws ParseException When malformed inline YAML string is parsed
255247
*/
256-
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array &$references = [])
248+
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array &$references = []): mixed
257249
{
258250
if (\in_array($scalar[$i], ['"', "'"], true)) {
259251
// quoted scalar
@@ -540,11 +532,9 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
540532
/**
541533
* Evaluates scalars and replaces magic values.
542534
*
543-
* @return mixed The evaluated YAML string
544-
*
545535
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
546536
*/
547-
private static function evaluateScalar(string $scalar, int $flags, array &$references = [])
537+
private static function evaluateScalar(string $scalar, int $flags, array &$references = []): mixed
548538
{
549539
$scalar = trim($scalar);
550540

@@ -744,8 +734,6 @@ private static function isBinaryString(string $value): bool
744734
/**
745735
* Gets a regex that matches a YAML date.
746736
*
747-
* @return string The regular expression
748-
*
749737
* @see http://www.yaml.org/spec/1.2/spec.html#id2761573
750738
*/
751739
private static function getTimestampRegex(): string

Parser.php

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ class Parser
4545
* @param string $filename The path to the YAML file to be parsed
4646
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
4747
*
48-
* @return mixed The YAML converted to a PHP value
49-
*
5048
* @throws ParseException If the file could not be read or the YAML is not valid
5149
*/
52-
public function parseFile(string $filename, int $flags = 0)
50+
public function parseFile(string $filename, int $flags = 0): mixed
5351
{
5452
if (!is_file($filename)) {
5553
throw new ParseException(sprintf('File "%s" does not exist.', $filename));
@@ -74,11 +72,9 @@ public function parseFile(string $filename, int $flags = 0)
7472
* @param string $value A YAML string
7573
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
7674
*
77-
* @return mixed A PHP value
78-
*
7975
* @throws ParseException If the YAML is not valid
8076
*/
81-
public function parse(string $value, int $flags = 0)
77+
public function parse(string $value, int $flags = 0): mixed
8278
{
8379
if (false === preg_match('//u', $value)) {
8480
throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
@@ -539,8 +535,6 @@ private function parseBlock(int $offset, string $yaml, int $flags)
539535
* Returns the current line number (takes the offset into account).
540536
*
541537
* @internal
542-
*
543-
* @return int The current line number
544538
*/
545539
public function getRealCurrentLineNb(): int
546540
{
@@ -557,11 +551,6 @@ public function getRealCurrentLineNb(): int
557551
return $realCurrentLineNumber;
558552
}
559553

560-
/**
561-
* Returns the current line indentation.
562-
*
563-
* @return int The current line indentation
564-
*/
565554
private function getCurrentLineIndentation(): int
566555
{
567556
if (' ' !== ($this->currentLine[0] ?? '')) {
@@ -577,8 +566,6 @@ private function getCurrentLineIndentation(): int
577566
* @param int|null $indentation The indent level at which the block is to be read, or null for default
578567
* @param bool $inSequence True if the enclosing data structure is a sequence
579568
*
580-
* @return string A YAML string
581-
*
582569
* @throws ParseException When indentation problem are detected
583570
*/
584571
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): string
@@ -718,11 +705,9 @@ private function moveToPreviousLine(): bool
718705
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
719706
* @param string $context The parser context (either sequence or mapping)
720707
*
721-
* @return mixed A PHP value
722-
*
723708
* @throws ParseException When reference does not exist
724709
*/
725-
private function parseValue(string $value, int $flags, string $context)
710+
private function parseValue(string $value, int $flags, string $context): mixed
726711
{
727712
if ('*' === ($value[0] ?? '')) {
728713
if (false !== $pos = strpos($value, '#')) {
@@ -938,8 +923,6 @@ private function parseBlockScalar(string $style, string $chomping = '', int $ind
938923

939924
/**
940925
* Returns true if the next line is indented.
941-
*
942-
* @return bool Returns true if the next line is indented, false otherwise
943926
*/
944927
private function isNextLineIndented(): bool
945928
{
@@ -967,31 +950,16 @@ private function isNextLineIndented(): bool
967950
return $ret;
968951
}
969952

970-
/**
971-
* Returns true if the current line is blank or if it is a comment line.
972-
*
973-
* @return bool Returns true if the current line is empty or if it is a comment line, false otherwise
974-
*/
975953
private function isCurrentLineEmpty(): bool
976954
{
977955
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
978956
}
979957

980-
/**
981-
* Returns true if the current line is blank.
982-
*
983-
* @return bool Returns true if the current line is blank, false otherwise
984-
*/
985958
private function isCurrentLineBlank(): bool
986959
{
987960
return '' === $this->currentLine || '' === trim($this->currentLine, ' ');
988961
}
989962

990-
/**
991-
* Returns true if the current line is a comment line.
992-
*
993-
* @return bool Returns true if the current line is a comment line, false otherwise
994-
*/
995963
private function isCurrentLineComment(): bool
996964
{
997965
//checking explicitly the first char of the trim is faster than loops or strpos
@@ -1005,13 +973,6 @@ private function isCurrentLineLastLineInDocument(): bool
1005973
return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
1006974
}
1007975

1008-
/**
1009-
* Cleanups a YAML string to be parsed.
1010-
*
1011-
* @param string $value The input YAML string
1012-
*
1013-
* @return string A cleaned up YAML string
1014-
*/
1015976
private function cleanup(string $value): string
1016977
{
1017978
$value = str_replace(["\r\n", "\r"], "\n", $value);
@@ -1043,11 +1004,6 @@ private function cleanup(string $value): string
10431004
return $value;
10441005
}
10451006

1046-
/**
1047-
* Returns true if the next line starts unindented collection.
1048-
*
1049-
* @return bool Returns true if the next line starts unindented collection, false otherwise
1050-
*/
10511007
private function isNextLineUnIndentedCollection(): bool
10521008
{
10531009
$currentIndentation = $this->getCurrentLineIndentation();
@@ -1074,11 +1030,6 @@ private function isNextLineUnIndentedCollection(): bool
10741030
return $ret;
10751031
}
10761032

1077-
/**
1078-
* Returns true if the string is un-indented collection item.
1079-
*
1080-
* @return bool Returns true if the string is un-indented collection item, false otherwise
1081-
*/
10821033
private function isStringUnIndentedCollectionItem(): bool
10831034
{
10841035
return 0 === strncmp($this->currentLine, '- ', 2) || '-' === rtrim($this->currentLine);

Yaml.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ class Yaml
4646
* @param string $filename The path to the YAML file to be parsed
4747
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
4848
*
49-
* @return mixed The YAML converted to a PHP value
50-
*
5149
* @throws ParseException If the file could not be read or the YAML is not valid
5250
*/
53-
public static function parseFile(string $filename, int $flags = 0)
51+
public static function parseFile(string $filename, int $flags = 0): mixed
5452
{
5553
$yaml = new Parser();
5654

@@ -69,11 +67,9 @@ public static function parseFile(string $filename, int $flags = 0)
6967
* @param string $input A string containing YAML
7068
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
7169
*
72-
* @return mixed The YAML converted to a PHP value
73-
*
7470
* @throws ParseException If the YAML is not valid
7571
*/
76-
public static function parse(string $input, int $flags = 0)
72+
public static function parse(string $input, int $flags = 0): mixed
7773
{
7874
$yaml = new Parser();
7975

@@ -90,8 +86,6 @@ public static function parse(string $input, int $flags = 0)
9086
* @param int $inline The level where you switch to inline YAML
9187
* @param int $indent The amount of spaces to use for indentation of nested nodes
9288
* @param int $flags A bit field of DUMP_* constants to customize the dumped YAML string
93-
*
94-
* @return string A YAML string representing the original PHP value
9589
*/
9690
public static function dump(mixed $input, int $inline = 2, int $indent = 4, int $flags = 0): string
9791
{

0 commit comments

Comments
 (0)