Skip to content

Commit 3dc414b

Browse files
derrabusnicolas-grekas
authored andcommitted
Fix inconsistent return points.
1 parent 5d61fdb commit 3dc414b

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

Command/LintCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,13 @@ private function getFiles($fileOrDirectory)
196196
}
197197
}
198198

199+
/**
200+
* @return string|null
201+
*/
199202
private function getStdin()
200203
{
201204
if (0 !== ftell(STDIN)) {
202-
return;
205+
return null;
203206
}
204207

205208
$inputs = '';

Inline.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
644644
case 'null' === $scalarLower:
645645
case '' === $scalar:
646646
case '~' === $scalar:
647-
return;
647+
return null;
648648
case 'true' === $scalarLower:
649649
return true;
650650
case 'false' === $scalarLower:
@@ -672,7 +672,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
672672
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
673673
}
674674

675-
return;
675+
return null;
676676
case 0 === strpos($scalar, '!!php/object:'):
677677
if (self::$objectSupport) {
678678
@trigger_error(self::getDeprecationMessage('The !!php/object: tag to indicate dumped PHP objects is deprecated since Symfony 3.1 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.'), E_USER_DEPRECATED);
@@ -684,7 +684,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
684684
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
685685
}
686686

687-
return;
687+
return null;
688688
case 0 === strpos($scalar, '!php/object'):
689689
if (self::$objectSupport) {
690690
return unserialize(self::parseScalar(substr($scalar, 12)));
@@ -694,7 +694,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
694694
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
695695
}
696696

697-
return;
697+
return null;
698698
case 0 === strpos($scalar, '!php/const:'):
699699
if (self::$constantSupport) {
700700
@trigger_error(self::getDeprecationMessage('The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.'), E_USER_DEPRECATED);
@@ -709,7 +709,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
709709
throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Have you forgotten to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
710710
}
711711

712-
return;
712+
return null;
713713
case 0 === strpos($scalar, '!php/const'):
714714
if (self::$constantSupport) {
715715
$i = 0;
@@ -723,7 +723,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
723723
throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Have you forgotten to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
724724
}
725725

726-
return;
726+
return null;
727727
case 0 === strpos($scalar, '!!float '):
728728
return (float) substr($scalar, 8);
729729
case 0 === strpos($scalar, '!!binary '):
@@ -795,7 +795,7 @@ private static function evaluateScalar($scalar, $flags, $references = [])
795795
private static function parseTag($value, &$i, $flags)
796796
{
797797
if ('!' !== $value[$i]) {
798-
return;
798+
return null;
799799
}
800800

801801
$tagLength = strcspn($value, " \t\n", $i + 1);
@@ -807,7 +807,7 @@ private static function parseTag($value, &$i, $flags)
807807
// Is followed by a scalar
808808
if ((!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && 'tagged' !== $tag) {
809809
// Manage non-whitelisted scalars in {@link self::evaluateScalar()}
810-
return;
810+
return null;
811811
}
812812

813813
// Built-in tags

Parser.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
564564
$oldLineIndentation = $this->getCurrentLineIndentation();
565565

566566
if (!$this->moveToNextLine()) {
567-
return;
567+
return '';
568568
}
569569

570570
if (null === $indentation) {
@@ -607,15 +607,15 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
607607
} else {
608608
$this->moveToPreviousLine();
609609

610-
return;
610+
return '';
611611
}
612612

613613
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
614614
// the previous line contained a dash but no item content, this line is a sequence item with the same indentation
615615
// and therefore no nested list or mapping
616616
$this->moveToPreviousLine();
617617

618-
return;
618+
return '';
619619
}
620620

621621
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
@@ -1102,14 +1102,17 @@ private function trimTag($value)
11021102
return $value;
11031103
}
11041104

1105+
/**
1106+
* @return string|null
1107+
*/
11051108
private function getLineTag($value, $flags, $nextLineCheck = true)
11061109
{
11071110
if ('' === $value || '!' !== $value[0] || 1 !== self::preg_match('/^'.self::TAG_PATTERN.' *( +#.*)?$/', $value, $matches)) {
1108-
return;
1111+
return null;
11091112
}
11101113

11111114
if ($nextLineCheck && !$this->isNextLineIndented()) {
1112-
return;
1115+
return null;
11131116
}
11141117

11151118
$tag = substr($matches['tag'], 1);

Tests/ParserTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public function testSpecifications($expected, $yaml, $comment, $deprecated)
4949
}
5050

5151
$deprecations[] = $msg;
52+
53+
return null;
5254
});
5355
}
5456

0 commit comments

Comments
 (0)