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 | 12 +++++++----- .../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 +- .../HttpKernel/CacheWarmer/CacheWarmerAggregate.php | 4 +++- .../ControllerMetadata/ArgumentMetadataFactory.php | 6 ++++-- .../Component/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, 62 insertions(+), 48 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index f14c38b36252a..c6d2e52cc1e11 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -168,6 +168,8 @@ public function getTypes($class, $property, array $context = []) 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 8ac21b12eb44b..acb183057161b 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -107,6 +107,8 @@ public static function collectDeprecations($outputFile) } $deprecations[] = [error_reporting(), $msg, $file]; + + return null; }); register_shutdown_function(function () use ($outputFile, &$deprecations) { @@ -125,7 +127,7 @@ public function handleError($type, $msg, $file, $line, $context = []) $deprecation = new Deprecation($msg, debug_backtrace(), $file); if ($deprecation->isMuted()) { - return; + return null; } $group = 'other'; @@ -164,6 +166,8 @@ public function handleError($type, $msg, $file, $line, $context = []) } ++$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 ac692ee62990c..a7bec8c1466e0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php @@ -145,6 +145,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } $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 9ec4df47a1323..432e7002dd048 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/StopwatchHelper.php @@ -39,12 +39,14 @@ public function getName() public function __call($method, $arguments = []) { - if (null !== $this->stopwatch) { - if (method_exists($this->stopwatch, $method)) { - return $this->stopwatch->{$method}(...$arguments); - } + if (null === $this->stopwatch) { + return null; + } - 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)); } } diff --git a/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php b/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php index 10e6ae4c81b4c..ea6ac36bbca08 100644 --- a/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php +++ b/src/Symfony/Bundle/WebServerBundle/WebServerConfig.php @@ -117,7 +117,7 @@ public function getDisplayAddress() 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 @@ private function findFrontController($documentRoot, $env) 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 df7d238e2d887..497504c5e9f88 100644 --- a/src/Symfony/Component/Cache/Traits/ArrayTrait.php +++ b/src/Symfony/Component/Cache/Traits/ArrayTrait.php @@ -131,7 +131,7 @@ private function freeze($value, $key) $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 ce2c28ba1a715..024d99d96643c 100644 --- a/src/Symfony/Component/Console/Output/ConsoleSectionOutput.php +++ b/src/Symfony/Component/Console/Output/ConsoleSectionOutput.php @@ -95,7 +95,9 @@ public function addContent(string $input) 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 7bdcaac629419..9508b2e3c3853 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -576,7 +576,9 @@ public function handleException($exception, array $error = null) $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 deeca8ad5fd0e..9ee1836aa9f31 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -276,6 +276,8 @@ private function make(string $id, int $invalidBehavior) 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 d19f799c79da9..26b761cd40bbd 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -592,7 +592,7 @@ private function doGet($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_ $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 1285334f58a77..925775aa567c3 100644 --- a/src/Symfony/Component/DependencyInjection/Extension/Extension.php +++ b/src/Symfony/Component/DependencyInjection/Extension/Extension.php @@ -101,7 +101,7 @@ public function getConfiguration(array $config, ContainerBuilder $container) 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 4fa3f8dff244b..7462b3192c80c 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1063,9 +1063,7 @@ private function relativize(string $xpath): string */ 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 @@ private function discoverNamespace(\DOMXPath $domxpath, string $prefix): ?string // 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 9212d246526eb..aa4629f2efa15 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 @@ public function __construct(bool $multiple = false) 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 20fab3a6eb6b4..a064361763d3f 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -100,6 +100,8 @@ public function __construct(CurlClientState $multi, $ch, array $options = null, return 1; // Abort the request } + + return null; }); } diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 2ee8dcbf8a41a..3bece1494cc01 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 f28fbd60cc952..57292e07f9bae 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php @@ -60,7 +60,7 @@ public function warmUp($cacheDir) if (isset($collectedLogs[$message])) { ++$collectedLogs[$message]['count']; - return; + return null; } $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); @@ -80,6 +80,8 @@ public function warmUp($cacheDir) '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 1757e9cb2c798..0a25338818a44 100644 --- a/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php +++ b/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php @@ -48,7 +48,7 @@ public function createArgumentMetadata($controller) private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function) { if (!$type = $parameter->getType()) { - return; + return null; } $name = $type->getName(); $lcName = strtolower($name); @@ -57,7 +57,7 @@ private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbs return $name; } if (!$function instanceof \ReflectionMethod) { - return; + return null; } if ('self' === $lcName) { return $function->getDeclaringClass()->name; @@ -65,5 +65,7 @@ private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbs 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 eb241675297a2..236bbd09b8b98 100644 --- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php +++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php @@ -101,5 +101,7 @@ private function getFileLinkFormat() ]; } } + + return null; } } diff --git a/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php b/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php index 8ed517fe42431..d30e8d4644b40 100644 --- a/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php +++ b/src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php @@ -84,13 +84,13 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, $te // 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 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, $te $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 fdfb09674ec69..3b9eba3a75c81 100644 --- a/src/Symfony/Component/Intl/Locale.php +++ b/src/Symfony/Component/Intl/Locale.php @@ -104,11 +104,7 @@ public static function getFallback($locale): ?string // 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 bacf0776205f2..111728cc05ffa 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1304,25 +1304,21 @@ private function getDescriptors(): array 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 78e517d1d51a7..c7a96d4bf9969 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -151,6 +151,8 @@ public function getTypes($class, $property, array $context = []) 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 46905fbfcd6dc..bfe2fd35162fe 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -566,7 +566,7 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere case 'null' === $scalarLower: case '' === $scalar: case '~' === $scalar: - return; + return null; case 'true' === $scalarLower: return true; case 'false' === $scalarLower: @@ -586,7 +586,7 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere 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 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere 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 50c195d1bfd04..ef53f2a5e6e8c 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -739,8 +739,6 @@ private function parseValue(string $value, int $flags, string $context) * @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 ceaef6fa14ba1..2bd57fd0f1219 100644 --- a/src/Symfony/Contracts/Service/ServiceSubscriberTrait.php +++ b/src/Symfony/Contracts/Service/ServiceSubscriberTrait.php @@ -57,5 +57,7 @@ public function setContainer(ContainerInterface $container) if (\is_callable(['parent', __FUNCTION__])) { return parent::setContainer($container); } + + return null; } }