@@ -45,11 +45,9 @@ class Parser
45
45
* @param string $filename The path to the YAML file to be parsed
46
46
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
47
47
*
48
- * @return mixed The YAML converted to a PHP value
49
- *
50
48
* @throws ParseException If the file could not be read or the YAML is not valid
51
49
*/
52
- public function parseFile (string $ filename , int $ flags = 0 )
50
+ public function parseFile (string $ filename , int $ flags = 0 ): mixed
53
51
{
54
52
if (!is_file ($ filename )) {
55
53
throw new ParseException (sprintf ('File "%s" does not exist. ' , $ filename ));
@@ -74,11 +72,9 @@ public function parseFile(string $filename, int $flags = 0)
74
72
* @param string $value A YAML string
75
73
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
76
74
*
77
- * @return mixed A PHP value
78
- *
79
75
* @throws ParseException If the YAML is not valid
80
76
*/
81
- public function parse (string $ value , int $ flags = 0 )
77
+ public function parse (string $ value , int $ flags = 0 ): mixed
82
78
{
83
79
if (false === preg_match ('//u ' , $ value )) {
84
80
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)
539
535
* Returns the current line number (takes the offset into account).
540
536
*
541
537
* @internal
542
- *
543
- * @return int The current line number
544
538
*/
545
539
public function getRealCurrentLineNb (): int
546
540
{
@@ -557,11 +551,6 @@ public function getRealCurrentLineNb(): int
557
551
return $ realCurrentLineNumber ;
558
552
}
559
553
560
- /**
561
- * Returns the current line indentation.
562
- *
563
- * @return int The current line indentation
564
- */
565
554
private function getCurrentLineIndentation (): int
566
555
{
567
556
if (' ' !== ($ this ->currentLine [0 ] ?? '' )) {
@@ -577,8 +566,6 @@ private function getCurrentLineIndentation(): int
577
566
* @param int|null $indentation The indent level at which the block is to be read, or null for default
578
567
* @param bool $inSequence True if the enclosing data structure is a sequence
579
568
*
580
- * @return string A YAML string
581
- *
582
569
* @throws ParseException When indentation problem are detected
583
570
*/
584
571
private function getNextEmbedBlock (int $ indentation = null , bool $ inSequence = false ): string
@@ -718,11 +705,9 @@ private function moveToPreviousLine(): bool
718
705
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
719
706
* @param string $context The parser context (either sequence or mapping)
720
707
*
721
- * @return mixed A PHP value
722
- *
723
708
* @throws ParseException When reference does not exist
724
709
*/
725
- private function parseValue (string $ value , int $ flags , string $ context )
710
+ private function parseValue (string $ value , int $ flags , string $ context ): mixed
726
711
{
727
712
if ('* ' === ($ value [0 ] ?? '' )) {
728
713
if (false !== $ pos = strpos ($ value , '# ' )) {
@@ -938,8 +923,6 @@ private function parseBlockScalar(string $style, string $chomping = '', int $ind
938
923
939
924
/**
940
925
* Returns true if the next line is indented.
941
- *
942
- * @return bool Returns true if the next line is indented, false otherwise
943
926
*/
944
927
private function isNextLineIndented (): bool
945
928
{
@@ -967,31 +950,16 @@ private function isNextLineIndented(): bool
967
950
return $ ret ;
968
951
}
969
952
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
- */
975
953
private function isCurrentLineEmpty (): bool
976
954
{
977
955
return $ this ->isCurrentLineBlank () || $ this ->isCurrentLineComment ();
978
956
}
979
957
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
- */
985
958
private function isCurrentLineBlank (): bool
986
959
{
987
960
return '' === $ this ->currentLine || '' === trim ($ this ->currentLine , ' ' );
988
961
}
989
962
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
- */
995
963
private function isCurrentLineComment (): bool
996
964
{
997
965
//checking explicitly the first char of the trim is faster than loops or strpos
@@ -1005,13 +973,6 @@ private function isCurrentLineLastLineInDocument(): bool
1005
973
return ($ this ->offset + $ this ->currentLineNb ) >= ($ this ->totalNumberOfLines - 1 );
1006
974
}
1007
975
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
- */
1015
976
private function cleanup (string $ value ): string
1016
977
{
1017
978
$ value = str_replace (["\r\n" , "\r" ], "\n" , $ value );
@@ -1043,11 +1004,6 @@ private function cleanup(string $value): string
1043
1004
return $ value ;
1044
1005
}
1045
1006
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
- */
1051
1007
private function isNextLineUnIndentedCollection (): bool
1052
1008
{
1053
1009
$ currentIndentation = $ this ->getCurrentLineIndentation ();
@@ -1074,11 +1030,6 @@ private function isNextLineUnIndentedCollection(): bool
1074
1030
return $ ret ;
1075
1031
}
1076
1032
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
- */
1082
1033
private function isStringUnIndentedCollectionItem (): bool
1083
1034
{
1084
1035
return 0 === strncmp ($ this ->currentLine , '- ' , 2 ) || '- ' === rtrim ($ this ->currentLine );
0 commit comments