From c26c53596eea8cc3acf27120c6e453c19d403b2c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 19 Aug 2019 23:30:37 +0200 Subject: [PATCH] Fix inconsistent return points. --- .../Doctrine/PropertyInfo/DoctrineExtractor.php | 2 ++ .../Bridge/PhpUnit/DeprecationErrorHandler.php | 6 +++++- .../Command/DebugAutowiringCommand.php | 2 ++ .../Templating/Helper/StopwatchHelper.php | 14 ++++++++------ .../Bundle/WebServerBundle/WebServerConfig.php | 8 +++++--- src/Symfony/Component/Cache/Traits/ArrayTrait.php | 2 +- .../Console/Output/ConsoleSectionOutput.php | 4 +++- src/Symfony/Component/Debug/ErrorHandler.php | 4 +++- .../Component/DependencyInjection/Container.php | 2 ++ .../DependencyInjection/ContainerBuilder.php | 2 +- .../DependencyInjection/Extension/Extension.php | 2 +- src/Symfony/Component/DomCrawler/Crawler.php | 10 ++-------- .../IntlTimeZoneToStringTransformer.php | 2 +- .../Component/HttpClient/Response/CurlResponse.php | 2 ++ src/Symfony/Component/HttpFoundation/Response.php | 2 +- .../CacheWarmer/CacheWarmerAggregate.php | 4 +++- .../ControllerMetadata/ArgumentMetadataFactory.php | 6 ++++-- .../HttpKernel/Debug/FileLinkFormatter.php | 2 ++ .../Intl/Data/Generator/TimezoneDataGenerator.php | 6 +++--- src/Symfony/Component/Intl/Locale.php | 6 +----- src/Symfony/Component/Process/Process.php | 12 ++++-------- .../PropertyInfo/Extractor/ReflectionExtractor.php | 2 ++ src/Symfony/Component/Yaml/Inline.php | 6 +++--- src/Symfony/Component/Yaml/Parser.php | 2 -- .../Contracts/Service/ServiceSubscriberTrait.php | 2 ++ 25 files changed, 63 insertions(+), 49 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index f14c38b362..c6d2e52cc1 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -168,6 +168,8 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE return $builtinType ? [new Type($builtinType, $nullable)] : null; } } + + return null; } /** diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 8ac21b12eb..acb1830571 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -107,6 +107,8 @@ class DeprecationErrorHandler } $deprecations[] = [error_reporting(), $msg, $file]; + + return null; }); register_shutdown_function(function () use ($outputFile, &$deprecations) { @@ -125,7 +127,7 @@ class DeprecationErrorHandler $deprecation = new Deprecation($msg, debug_backtrace(), $file); if ($deprecation->isMuted()) { - return; + return null; } $group = 'other'; @@ -164,6 +166,8 @@ class DeprecationErrorHandler } ++$this->deprecations[$group.'Count']; + + return null; } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php index ac692ee629..a7bec8c146 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php @@ -145,6 +145,8 @@ EOF } $io->newLine(); + + return null; } private function getFileLink(string $class): string diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php index 9ec4df47a1..432e7002dd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php @@ -39,12 +39,14 @@ class StopwatchHelper extends Helper public function __call($method, $arguments = []) { - if (null !== $this->stopwatch) { - if (method_exists($this->stopwatch, $method)) { - return $this->stopwatch->{$method}(...$arguments); - } - - throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method)); + if (null === $this->stopwatch) { + return null; } + + if (method_exists($this->stopwatch, $method)) { + return $this->stopwatch->{$method}(...$arguments); + } + + throw new \BadMethodCallException(sprintf('Method "%s" of Stopwatch does not exist', $method)); } } diff --git a/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php b/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php index 10e6ae4c81..ea6ac36bbc 100644 --- a/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php +++ b/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php @@ -117,7 +117,7 @@ class WebServerConfig return gethostbyname($localHostname).':'.$this->port; } - private function findFrontController($documentRoot, $env) + private function findFrontController(string $documentRoot, string $env): ?string { $fileNames = $this->getFrontControllerFileNames($env); @@ -126,14 +126,16 @@ class WebServerConfig 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']; } - private function findBestPort() + private function findBestPort(): int { $port = 8000; while (false !== $fp = @fsockopen($this->hostname, $port, $errno, $errstr, 1)) { diff --git a/src/Symfony/Component/Cache/Traits/ArrayTrait.php b/src/Symfony/Component/Cache/Traits/ArrayTrait.php index df7d238e2d..497504c5e9 100644 --- a/src/Symfony/Component/Cache/Traits/ArrayTrait.php +++ b/src/Symfony/Component/Cache/Traits/ArrayTrait.php @@ -131,7 +131,7 @@ trait ArrayTrait $message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage()); CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]); - return; + return null; } // 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)) { diff --git a/src/Symfony/Component/Console/Output/ConsoleSectionOutput.php b/src/Symfony/Component/Console/Output/ConsoleSectionOutput.php index ce2c28ba1a..024d99d966 100644 --- a/src/Symfony/Component/Console/Output/ConsoleSectionOutput.php +++ b/src/Symfony/Component/Console/Output/ConsoleSectionOutput.php @@ -95,7 +95,9 @@ class ConsoleSectionOutput extends StreamOutput protected function doWrite($message, $newline) { if (!$this->isDecorated()) { - return parent::doWrite($message, $newline); + parent::doWrite($message, $newline); + + return; } $erasedContent = $this->popStreamContentUntilCurrentSection(); diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 7bdcaac629..9508b2e3c3 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -576,7 +576,9 @@ class ErrorHandler $this->exceptionHandler = null; try { if (null !== $exceptionHandler) { - return $exceptionHandler($exception); + $exceptionHandler($exception); + + return; } $handlerException = $handlerException ?: $exception; } catch (\Throwable $handlerException) { diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index deeca8ad5f..9ee1836aa9 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -276,6 +276,8 @@ class Container implements ResettableContainerInterface throw new ServiceNotFoundException($id, null, null, $alternatives); } + + return null; } /** diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index d19f799c79..26b761cd40 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -592,7 +592,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface $definition = $this->getDefinition($id); } catch (ServiceNotFoundException $e) { if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE < $invalidBehavior) { - return; + return null; } throw $e; diff --git a/src/Symfony/Component/DependencyInjection/Extension/Extension.php b/src/Symfony/Component/DependencyInjection/Extension/Extension.php index 1285334f58..925775aa56 100644 --- a/src/Symfony/Component/DependencyInjection/Extension/Extension.php +++ b/src/Symfony/Component/DependencyInjection/Extension/Extension.php @@ -101,7 +101,7 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn return null; } - final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) + final protected function processConfiguration(ConfigurationInterface $configuration, array $configs): array { $processor = new Processor(); diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 4fa3f8dff2..7462b3192c 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1063,9 +1063,7 @@ class Crawler implements \Countable, \IteratorAggregate */ public function getNode($position) { - if (isset($this->nodes[$position])) { - return $this->nodes[$position]; - } + return isset($this->nodes[$position]) ? $this->nodes[$position] : null; } /** @@ -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 $namespaces = $domxpath->query(sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix)); - if ($node = $namespaces->item(0)) { - return $node->nodeValue; - } - - return null; + return ($node = $namespaces->item(0)) ? $node->nodeValue : null; } private function findNamespacePrefixes(string $xpath): array diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php index 9212d24652..aa4629f2ef 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php @@ -34,7 +34,7 @@ class IntlTimeZoneToStringTransformer implements DataTransformerInterface public function transform($intlTimeZone) { if (null === $intlTimeZone) { - return; + return null; } if ($this->multiple) { diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index 20fab3a6eb..a064361763 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -100,6 +100,8 @@ final class CurlResponse implements ResponseInterface return 1; // Abort the request } + + return null; }); } diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 2ee8dcbf8a..3bece1494c 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -88,7 +88,7 @@ class Response const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 /** - * @var \Symfony\Component\HttpFoundation\ResponseHeaderBag + * @var ResponseHeaderBag */ public $headers; diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php index f28fbd60cc..57292e07f9 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php @@ -60,7 +60,7 @@ class CacheWarmerAggregate implements CacheWarmerInterface if (isset($collectedLogs[$message])) { ++$collectedLogs[$message]['count']; - return; + return null; } $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); @@ -80,6 +80,8 @@ class CacheWarmerAggregate implements CacheWarmerInterface 'trace' => $backtrace, 'count' => 1, ]; + + return null; }); } diff --git a/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php b/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php index 1757e9cb2c..0a25338818 100644 --- a/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php +++ b/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php @@ -48,7 +48,7 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function) { if (!$type = $parameter->getType()) { - return; + return null; } $name = $type->getName(); $lcName = strtolower($name); @@ -57,7 +57,7 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface return $name; } if (!$function instanceof \ReflectionMethod) { - return; + return null; } if ('self' === $lcName) { return $function->getDeclaringClass()->name; @@ -65,5 +65,7 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface if ($parent = $function->getDeclaringClass()->getParentClass()) { return $parent->name; } + + return null; } } diff --git a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php index eb24167529..236bbd09b8 100644 --- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php +++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php @@ -101,5 +101,7 @@ class FileLinkFormatter ]; } } + + return null; } } diff --git a/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php b/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php index 8ed517fe42..d30e8d4644 100644 --- a/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php +++ b/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php @@ -84,13 +84,13 @@ class TimezoneDataGenerator extends AbstractDataGenerator // Don't generate aliases, as they are resolved during runtime // Unless an alias is needed as fallback for de-duplication purposes if (isset($this->localeAliases[$displayLocale]) && !$this->generatingFallback) { - return; + return null; } $localeBundle = $reader->read($tempDir, $displayLocale); if (!isset($localeBundle['zoneStrings']) || null === $localeBundle['zoneStrings']) { - return; + return null; } $data = [ @@ -115,7 +115,7 @@ class TimezoneDataGenerator extends AbstractDataGenerator $data['Meta'] = array_diff($data['Meta'], $fallback['Meta']); } if (!$data['Names'] && !$data['Meta']) { - return; + return null; } $this->zoneIds = array_merge($this->zoneIds, array_keys($data['Names'])); diff --git a/src/Symfony/Component/Intl/Locale.php b/src/Symfony/Component/Intl/Locale.php index fdfb09674e..3b9eba3a75 100644 --- a/src/Symfony/Component/Intl/Locale.php +++ b/src/Symfony/Component/Intl/Locale.php @@ -104,11 +104,7 @@ final class Locale extends \Locale // Don't return default fallback for "root", "meta" or others // Normal locales have two or three letters - if (\strlen($locale) < 4) { - return self::$defaultFallback; - } - - return null; + return \strlen($locale) < 4 ? self::$defaultFallback : null; } /** diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index bacf077620..111728cc05 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1304,25 +1304,21 @@ class Process implements \IteratorAggregate protected function buildCallback(callable $callback = null) { if ($this->outputDisabled) { - return function ($type, $data) use ($callback) { - if (null !== $callback) { - return $callback($type, $data); - } + return function ($type, $data) use ($callback): bool { + return null !== $callback && $callback($type, $data); }; } $out = self::OUT; - return function ($type, $data) use ($callback, $out) { + return function ($type, $data) use ($callback, $out): bool { if ($out == $type) { $this->addOutput($data); } else { $this->addErrorOutput($data); } - if (null !== $callback) { - return $callback($type, $data); - } + return null !== $callback && $callback($type, $data); }; } diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 78e517d1d5..c7a96d4bf9 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -151,6 +151,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp if ($fromDefaultValue = $this->extractFromDefaultValue($class, $property)) { return $fromDefaultValue; } + + return null; } /** diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 46905fbfcd..bfe2fd3516 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -566,7 +566,7 @@ class Inline case 'null' === $scalarLower: case '' === $scalar: case '~' === $scalar: - return; + return null; case 'true' === $scalarLower: return true; 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); } - return; + return null; case 0 === strpos($scalar, '!php/const'): if (self::$constantSupport) { $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); } - return; + return null; case 0 === strpos($scalar, '!!float '): return (float) substr($scalar, 8); case 0 === strpos($scalar, '!!binary '): diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 50c195d1bf..ef53f2a5e6 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -739,8 +739,6 @@ class Parser * @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 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 { diff --git a/src/Symfony/Contracts/Service/ServiceSubscriberTrait.php b/src/Symfony/Contracts/Service/ServiceSubscriberTrait.php index ceaef6fa14..2bd57fd0f1 100644 --- a/src/Symfony/Contracts/Service/ServiceSubscriberTrait.php +++ b/src/Symfony/Contracts/Service/ServiceSubscriberTrait.php @@ -57,5 +57,7 @@ trait ServiceSubscriberTrait if (\is_callable(['parent', __FUNCTION__])) { return parent::setContainer($container); } + + return null; } }