minor #33254 Fix inconsistent return points (derrabus)

This PR was merged into the 4.3 branch.

Discussion
----------

Fix inconsistent return points

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17201 in preparation for #33228
| License       | MIT
| Doc PR        | N/A

That's #33252 on the 4.3 branch.

Commits
-------

c26c53596e Fix inconsistent return points.
This commit is contained in:
Nicolas Grekas 2019-08-20 16:28:49 +02:00
commit cfb218456c
25 changed files with 63 additions and 49 deletions

View File

@ -168,6 +168,8 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
return $builtinType ? [new Type($builtinType, $nullable)] : null; return $builtinType ? [new Type($builtinType, $nullable)] : null;
} }
} }
return null;
} }
/** /**

View File

@ -107,6 +107,8 @@ class DeprecationErrorHandler
} }
$deprecations[] = [error_reporting(), $msg, $file]; $deprecations[] = [error_reporting(), $msg, $file];
return null;
}); });
register_shutdown_function(function () use ($outputFile, &$deprecations) { register_shutdown_function(function () use ($outputFile, &$deprecations) {
@ -125,7 +127,7 @@ class DeprecationErrorHandler
$deprecation = new Deprecation($msg, debug_backtrace(), $file); $deprecation = new Deprecation($msg, debug_backtrace(), $file);
if ($deprecation->isMuted()) { if ($deprecation->isMuted()) {
return; return null;
} }
$group = 'other'; $group = 'other';
@ -164,6 +166,8 @@ class DeprecationErrorHandler
} }
++$this->deprecations[$group.'Count']; ++$this->deprecations[$group.'Count'];
return null;
} }
/** /**

View File

@ -145,6 +145,8 @@ EOF
} }
$io->newLine(); $io->newLine();
return null;
} }
private function getFileLink(string $class): string private function getFileLink(string $class): string

View File

@ -39,12 +39,14 @@ class StopwatchHelper extends Helper
public function __call($method, $arguments = []) public function __call($method, $arguments = [])
{ {
if (null !== $this->stopwatch) { if (null === $this->stopwatch) {
if (method_exists($this->stopwatch, $method)) { return null;
return $this->stopwatch->{$method}(...$arguments);
}
throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method));
} }
if (method_exists($this->stopwatch, $method)) {
return $this->stopwatch->{$method}(...$arguments);
}
throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method));
} }
} }

View File

@ -117,7 +117,7 @@ class WebServerConfig
return gethostbyname($localHostname).':'.$this->port; return gethostbyname($localHostname).':'.$this->port;
} }
private function findFrontController($documentRoot, $env) private function findFrontController(string $documentRoot, string $env): ?string
{ {
$fileNames = $this->getFrontControllerFileNames($env); $fileNames = $this->getFrontControllerFileNames($env);
@ -126,14 +126,16 @@ class WebServerConfig
return $fileName; return $fileName;
} }
} }
return null;
} }
private function getFrontControllerFileNames($env) private function getFrontControllerFileNames(string $env): array
{ {
return ['app_'.$env.'.php', 'app.php', 'index_'.$env.'.php', 'index.php']; return ['app_'.$env.'.php', 'app.php', 'index_'.$env.'.php', 'index.php'];
} }
private function findBestPort() private function findBestPort(): int
{ {
$port = 8000; $port = 8000;
while (false !== $fp = @fsockopen($this->hostname, $port, $errno, $errstr, 1)) { while (false !== $fp = @fsockopen($this->hostname, $port, $errno, $errstr, 1)) {

View File

@ -131,7 +131,7 @@ trait ArrayTrait
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage()); $message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]); CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);
return; return null;
} }
// Keep value serialized if it contains any objects or any internal references // Keep value serialized if it contains any objects or any internal references
if ('C' === $serialized[0] || 'O' === $serialized[0] || preg_match('/;[OCRr]:[1-9]/', $serialized)) { if ('C' === $serialized[0] || 'O' === $serialized[0] || preg_match('/;[OCRr]:[1-9]/', $serialized)) {

View File

@ -95,7 +95,9 @@ class ConsoleSectionOutput extends StreamOutput
protected function doWrite($message, $newline) protected function doWrite($message, $newline)
{ {
if (!$this->isDecorated()) { if (!$this->isDecorated()) {
return parent::doWrite($message, $newline); parent::doWrite($message, $newline);
return;
} }
$erasedContent = $this->popStreamContentUntilCurrentSection(); $erasedContent = $this->popStreamContentUntilCurrentSection();

View File

@ -576,7 +576,9 @@ class ErrorHandler
$this->exceptionHandler = null; $this->exceptionHandler = null;
try { try {
if (null !== $exceptionHandler) { if (null !== $exceptionHandler) {
return $exceptionHandler($exception); $exceptionHandler($exception);
return;
} }
$handlerException = $handlerException ?: $exception; $handlerException = $handlerException ?: $exception;
} catch (\Throwable $handlerException) { } catch (\Throwable $handlerException) {

View File

@ -276,6 +276,8 @@ class Container implements ResettableContainerInterface
throw new ServiceNotFoundException($id, null, null, $alternatives); throw new ServiceNotFoundException($id, null, null, $alternatives);
} }
return null;
} }
/** /**

View File

@ -592,7 +592,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
$definition = $this->getDefinition($id); $definition = $this->getDefinition($id);
} catch (ServiceNotFoundException $e) { } catch (ServiceNotFoundException $e) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE < $invalidBehavior) { if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE < $invalidBehavior) {
return; return null;
} }
throw $e; throw $e;

View File

@ -101,7 +101,7 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn
return null; return null;
} }
final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) final protected function processConfiguration(ConfigurationInterface $configuration, array $configs): array
{ {
$processor = new Processor(); $processor = new Processor();

View File

@ -1063,9 +1063,7 @@ class Crawler implements \Countable, \IteratorAggregate
*/ */
public function getNode($position) public function getNode($position)
{ {
if (isset($this->nodes[$position])) { return isset($this->nodes[$position]) ? $this->nodes[$position] : null;
return $this->nodes[$position];
}
} }
/** /**
@ -1180,11 +1178,7 @@ class Crawler implements \Countable, \IteratorAggregate
// ask for one namespace, otherwise we'd get a collection with an item for each node // ask for one namespace, otherwise we'd get a collection with an item for each node
$namespaces = $domxpath->query(sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix)); $namespaces = $domxpath->query(sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix));
if ($node = $namespaces->item(0)) { return ($node = $namespaces->item(0)) ? $node->nodeValue : null;
return $node->nodeValue;
}
return null;
} }
private function findNamespacePrefixes(string $xpath): array private function findNamespacePrefixes(string $xpath): array

View File

@ -34,7 +34,7 @@ class IntlTimeZoneToStringTransformer implements DataTransformerInterface
public function transform($intlTimeZone) public function transform($intlTimeZone)
{ {
if (null === $intlTimeZone) { if (null === $intlTimeZone) {
return; return null;
} }
if ($this->multiple) { if ($this->multiple) {

View File

@ -100,6 +100,8 @@ final class CurlResponse implements ResponseInterface
return 1; // Abort the request return 1; // Abort the request
} }
return null;
}); });
} }

View File

@ -88,7 +88,7 @@ class Response
const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585
/** /**
* @var \Symfony\Component\HttpFoundation\ResponseHeaderBag * @var ResponseHeaderBag
*/ */
public $headers; public $headers;

View File

@ -60,7 +60,7 @@ class CacheWarmerAggregate implements CacheWarmerInterface
if (isset($collectedLogs[$message])) { if (isset($collectedLogs[$message])) {
++$collectedLogs[$message]['count']; ++$collectedLogs[$message]['count'];
return; return null;
} }
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
@ -80,6 +80,8 @@ class CacheWarmerAggregate implements CacheWarmerInterface
'trace' => $backtrace, 'trace' => $backtrace,
'count' => 1, 'count' => 1,
]; ];
return null;
}); });
} }

View File

@ -48,7 +48,7 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function) private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
{ {
if (!$type = $parameter->getType()) { if (!$type = $parameter->getType()) {
return; return null;
} }
$name = $type->getName(); $name = $type->getName();
$lcName = strtolower($name); $lcName = strtolower($name);
@ -57,7 +57,7 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
return $name; return $name;
} }
if (!$function instanceof \ReflectionMethod) { if (!$function instanceof \ReflectionMethod) {
return; return null;
} }
if ('self' === $lcName) { if ('self' === $lcName) {
return $function->getDeclaringClass()->name; return $function->getDeclaringClass()->name;
@ -65,5 +65,7 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
if ($parent = $function->getDeclaringClass()->getParentClass()) { if ($parent = $function->getDeclaringClass()->getParentClass()) {
return $parent->name; return $parent->name;
} }
return null;
} }
} }

View File

@ -101,5 +101,7 @@ class FileLinkFormatter
]; ];
} }
} }
return null;
} }
} }

View File

@ -84,13 +84,13 @@ class TimezoneDataGenerator extends AbstractDataGenerator
// Don't generate aliases, as they are resolved during runtime // Don't generate aliases, as they are resolved during runtime
// Unless an alias is needed as fallback for de-duplication purposes // Unless an alias is needed as fallback for de-duplication purposes
if (isset($this->localeAliases[$displayLocale]) && !$this->generatingFallback) { if (isset($this->localeAliases[$displayLocale]) && !$this->generatingFallback) {
return; return null;
} }
$localeBundle = $reader->read($tempDir, $displayLocale); $localeBundle = $reader->read($tempDir, $displayLocale);
if (!isset($localeBundle['zoneStrings']) || null === $localeBundle['zoneStrings']) { if (!isset($localeBundle['zoneStrings']) || null === $localeBundle['zoneStrings']) {
return; return null;
} }
$data = [ $data = [
@ -115,7 +115,7 @@ class TimezoneDataGenerator extends AbstractDataGenerator
$data['Meta'] = array_diff($data['Meta'], $fallback['Meta']); $data['Meta'] = array_diff($data['Meta'], $fallback['Meta']);
} }
if (!$data['Names'] && !$data['Meta']) { if (!$data['Names'] && !$data['Meta']) {
return; return null;
} }
$this->zoneIds = array_merge($this->zoneIds, array_keys($data['Names'])); $this->zoneIds = array_merge($this->zoneIds, array_keys($data['Names']));

View File

@ -104,11 +104,7 @@ final class Locale extends \Locale
// Don't return default fallback for "root", "meta" or others // Don't return default fallback for "root", "meta" or others
// Normal locales have two or three letters // Normal locales have two or three letters
if (\strlen($locale) < 4) { return \strlen($locale) < 4 ? self::$defaultFallback : null;
return self::$defaultFallback;
}
return null;
} }
/** /**

View File

@ -1304,25 +1304,21 @@ class Process implements \IteratorAggregate
protected function buildCallback(callable $callback = null) protected function buildCallback(callable $callback = null)
{ {
if ($this->outputDisabled) { if ($this->outputDisabled) {
return function ($type, $data) use ($callback) { return function ($type, $data) use ($callback): bool {
if (null !== $callback) { return null !== $callback && $callback($type, $data);
return $callback($type, $data);
}
}; };
} }
$out = self::OUT; $out = self::OUT;
return function ($type, $data) use ($callback, $out) { return function ($type, $data) use ($callback, $out): bool {
if ($out == $type) { if ($out == $type) {
$this->addOutput($data); $this->addOutput($data);
} else { } else {
$this->addErrorOutput($data); $this->addErrorOutput($data);
} }
if (null !== $callback) { return null !== $callback && $callback($type, $data);
return $callback($type, $data);
}
}; };
} }

View File

@ -151,6 +151,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
if ($fromDefaultValue = $this->extractFromDefaultValue($class, $property)) { if ($fromDefaultValue = $this->extractFromDefaultValue($class, $property)) {
return $fromDefaultValue; return $fromDefaultValue;
} }
return null;
} }
/** /**

View File

@ -566,7 +566,7 @@ class Inline
case 'null' === $scalarLower: case 'null' === $scalarLower:
case '' === $scalar: case '' === $scalar:
case '~' === $scalar: case '~' === $scalar:
return; return null;
case 'true' === $scalarLower: case 'true' === $scalarLower:
return true; return true;
case 'false' === $scalarLower: case 'false' === $scalarLower:
@ -586,7 +586,7 @@ class Inline
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename); throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
} }
return; return null;
case 0 === strpos($scalar, '!php/const'): case 0 === strpos($scalar, '!php/const'):
if (self::$constantSupport) { if (self::$constantSupport) {
$i = 0; $i = 0;
@ -600,7 +600,7 @@ class Inline
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); 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);
} }
return; return null;
case 0 === strpos($scalar, '!!float '): case 0 === strpos($scalar, '!!float '):
return (float) substr($scalar, 8); return (float) substr($scalar, 8);
case 0 === strpos($scalar, '!!binary '): case 0 === strpos($scalar, '!!binary '):

View File

@ -739,8 +739,6 @@ class Parser
* @param string $style The style indicator that was used to begin this block scalar (| or >) * @param string $style The style indicator that was used to begin this block scalar (| or >)
* @param string $chomping The chomping indicator that was used to begin this block scalar (+ or -) * @param string $chomping The chomping indicator that was used to begin this block scalar (+ or -)
* @param int $indentation The indentation indicator that was used to begin this block scalar * @param int $indentation The indentation indicator that was used to begin this block scalar
*
* @return string The text value
*/ */
private function parseBlockScalar(string $style, string $chomping = '', int $indentation = 0): string private function parseBlockScalar(string $style, string $chomping = '', int $indentation = 0): string
{ {

View File

@ -57,5 +57,7 @@ trait ServiceSubscriberTrait
if (\is_callable(['parent', __FUNCTION__])) { if (\is_callable(['parent', __FUNCTION__])) {
return parent::setContainer($container); return parent::setContainer($container);
} }
return null;
} }
} }