Skip to content

Commit

Permalink
minor #33252 Fix inconsistent return points (derrabus)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

Fix inconsistent return points

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| 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

Inconsistent return points in methods prevent adding return types. I thought, I'll give it a try and fix them. After this PR, PhpStorm's inspection still finds 39 issues, but as far as I can tell, they're either false positives or fixture code.

Commits
-------

f5b6ee9 Fix inconsistent return points.
  • Loading branch information
nicolas-grekas committed Aug 20, 2019
2 parents 55a484d + f5b6ee9 commit 8069b58
Show file tree
Hide file tree
Showing 131 changed files with 420 additions and 210 deletions.
Expand Up @@ -37,7 +37,7 @@ public function __construct(Cache $cache)
public function fetch($key)
{
if (false === $value = $this->cache->fetch($key)) {
return;
return null;
}

return $value;
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
Expand Up @@ -118,6 +118,8 @@ public function guessRequired($class, $property)

return new ValueGuess(!$mapping['joinColumns'][0]['nullable'], Guess::HIGH_CONFIDENCE);
}

return null;
}

/**
Expand All @@ -137,6 +139,8 @@ public function guessMaxLength($class, $property)
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}

return null;
}

/**
Expand All @@ -150,6 +154,8 @@ public function guessPattern($class, $property)
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}

return null;
}

protected function getMetadata($class)
Expand All @@ -171,5 +177,7 @@ protected function getMetadata($class)
// not an entity or mapped super class, using Doctrine ORM 2.2
}
}

return null;
}
}
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Expand Up @@ -157,6 +157,8 @@ public function configureOptions(OptionsResolver $resolver)

return $doctrineChoiceLoader;
}

return null;
};

$choiceName = function (Options $options) {
Expand All @@ -171,6 +173,7 @@ public function configureOptions(OptionsResolver $resolver)
}

// Otherwise, an incrementing integer is used as name automatically
return null;
};

// The choices are always indexed by ID (see "choices" normalizer
Expand All @@ -187,6 +190,7 @@ public function configureOptions(OptionsResolver $resolver)
}

// Otherwise, an incrementing integer is used as value automatically
return null;
};

$emNormalizer = function (Options $options, $em) {
Expand Down
Expand Up @@ -248,6 +248,8 @@ private function getMergeSql()
return "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->timeCol) VALUES (:id, :data, :time) ".
"ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->timeCol)";
}

return null;
}

private function getServerVersion()
Expand Down
12 changes: 8 additions & 4 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Expand Up @@ -42,9 +42,9 @@ public function getProperties($class, array $context = [])
try {
$metadata = $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException $exception) {
return;
return null;
} catch (OrmMappingException $exception) {
return;
return null;
}

$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
Expand All @@ -68,9 +68,9 @@ public function getTypes($class, $property, array $context = [])
try {
$metadata = $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException $exception) {
return;
return null;
} catch (OrmMappingException $exception) {
return;
return null;
}

if ($metadata->hasAssociation($property)) {
Expand Down Expand Up @@ -162,6 +162,8 @@ public function getTypes($class, $property, array $context = [])
return $builtinType ? [new Type($builtinType, $nullable)] : null;
}
}

return null;
}

/**
Expand Down Expand Up @@ -225,5 +227,7 @@ private function getPhpType($doctrineType)
case DBALType::OBJECT:
return Type::BUILTIN_TYPE_OBJECT;
}

return null;
}
}
Expand Up @@ -47,7 +47,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (null === $value) {
return;
return null;
}
if (!$value instanceof Foo) {
throw new ConversionException(sprintf('Expected %s, got %s', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\Foo', \gettype($value)));
Expand All @@ -62,7 +62,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (null === $value) {
return;
return null;
}
if (!\is_string($value)) {
throw ConversionException::conversionFailed($value, self::NAME);
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/PhpUnit/ClockMock.php
Expand Up @@ -25,6 +25,8 @@ public static function withClockMock($enable = null)
}

self::$now = is_numeric($enable) ? (float) $enable : ($enable ? microtime(true) : null);

return null;
}

public static function time()
Expand Down Expand Up @@ -54,6 +56,8 @@ public static function usleep($us)
}

self::$now += $us / 1000000;

return null;
}

public static function microtime($asFloat = false)
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Expand Up @@ -180,6 +180,8 @@ public static function register($mode = 0)
++$ref;
}
++$deprecations[$group.'Count'];

return null;
};
$oldErrorHandler = set_error_handler($deprecationHandler);

Expand Down Expand Up @@ -291,6 +293,8 @@ public static function collectDeprecations($outputFile)
return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
}
$deprecations[] = array(error_reporting(), $msg, $file);

return null;
});

register_shutdown_function(function () use ($outputFile, &$deprecations) {
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerTrait.php
Expand Up @@ -95,11 +95,7 @@ private function findSutFqcn($test)
$sutFqcn = str_replace('\\Tests\\', '\\', $class);
$sutFqcn = preg_replace('{Test$}', '', $sutFqcn);

if (!class_exists($sutFqcn)) {
return;
}

return $sutFqcn;
return class_exists($sutFqcn) ? $sutFqcn : null;
}

public function __destruct()
Expand Down
Expand Up @@ -357,6 +357,8 @@ public function handleError($type, $msg, $file, $line, $context = array())
$msg = 'Unsilenced deprecation: '.$msg;
}
$this->gatheredDeprecations[] = $msg;

return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/bin/simple-phpunit
Expand Up @@ -135,7 +135,7 @@ $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
$argc = isset($_SERVER['argc']) ? $_SERVER['argc'] : 0;

if ($PHPUNIT_VERSION < 8.0) {
$argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; });
$argv = array_filter($argv, function ($v) use (&$argc) { if ('--do-not-cache-result' !== $v) return true; --$argc; return false; });
} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), FILTER_VALIDATE_BOOLEAN)) {
$argv[] = '--do-not-cache-result';
++$argc;
Expand Down
Expand Up @@ -46,7 +46,7 @@ public static function generate(string $returnedValueExpression, ?\ReflectionMet
$functionLoader = $functionLoader[0];
}
if (!\is_object($functionLoader)) {
return;
return null;
}
if ($functionLoader instanceof ClassLoader) {
return $functionLoader;
Expand All @@ -57,6 +57,8 @@ public static function generate(string $returnedValueExpression, ?\ReflectionMet
if ($functionLoader instanceof \Symfony\Component\ErrorHandler\DebugClassLoader) {
return $getComposerClassLoader($functionLoader->getClassLoader());
}

return null;
};

$classLoader = null;
Expand Down
9 changes: 3 additions & 6 deletions src/Symfony/Bridge/Twig/AppVariable.php
Expand Up @@ -83,9 +83,8 @@ public function getUser()
}

$user = $token->getUser();
if (\is_object($user)) {
return $user;
}

return \is_object($user) ? $user : null;
}

/**
Expand Down Expand Up @@ -113,9 +112,7 @@ public function getSession()
throw new \RuntimeException('The "app.session" variable is not available.');
}

if ($request = $this->getRequest()) {
return $request->getSession();
}
return ($request = $this->getRequest()) ? $request->getSession() : null;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Expand Up @@ -220,16 +220,16 @@ private function getMetadata($type, $entity)
return $entity;
}
if ('tests' === $type) {
return;
return null;
}
if ('functions' === $type || 'filters' === $type) {
$cb = $entity->getCallable();
if (null === $cb) {
return;
return null;
}
if (\is_array($cb)) {
if (!method_exists($cb[0], $cb[1])) {
return;
return null;
}
$refl = new \ReflectionMethod($cb[0], $cb[1]);
} elseif (\is_object($cb) && method_exists($cb, '__invoke')) {
Expand Down Expand Up @@ -268,6 +268,8 @@ private function getMetadata($type, $entity)

return $args;
}

return null;
}

private function getPrettyMetadata($type, $entity, $decorated)
Expand Down Expand Up @@ -302,5 +304,7 @@ private function getPrettyMetadata($type, $entity, $decorated)
if ('filters' === $type) {
return $meta ? '('.implode(', ', $meta).')' : '';
}

return null;
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/DumpExtension.php
Expand Up @@ -55,7 +55,7 @@ public function getName()
public function dump(Environment $env, $context)
{
if (!$env->isDebug()) {
return;
return null;
}

if (2 === \func_num_args()) {
Expand Down
Expand Up @@ -115,7 +115,7 @@ private function getReadDomainFromArguments(Node $arguments, $index)
} elseif ($arguments->hasNode($index)) {
$argument = $arguments->getNode($index);
} else {
return;
return null;
}

return $this->getReadDomainFromNode($argument);
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/Twig/UndefinedCallableHandler.php
Expand Up @@ -71,6 +71,8 @@ public static function onUndefinedFilter($name)
}

self::onUndefined($name, 'filter', self::$filterComponents[$name]);

return true;
}

public static function onUndefinedFunction($name)
Expand All @@ -80,6 +82,8 @@ public static function onUndefinedFunction($name)
}

self::onUndefined($name, 'function', self::$functionComponents[$name]);

return true;
}

private static function onUndefined($name, $type, $component)
Expand Down
Expand Up @@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>config:dump-reference FrameworkBundle profiler.matcher</comment> to dump the <comment>framework.profiler.matcher</comment> configuration)',
]);

return;
return null;
}

$extension = $this->findExtension($name);
Expand Down Expand Up @@ -129,5 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));

return null;
}
}
Expand Up @@ -93,5 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$io->table([], $tableRows);

return null;
}
}
Expand Up @@ -154,10 +154,13 @@ private function convertController(Route $route)
}
}

/**
* @return callable|null
*/
private function extractCallable(Route $route)
{
if (!$route->hasDefault('_controller')) {
return;
return null;
}

$controller = $route->getDefault('_controller');
Expand All @@ -178,5 +181,7 @@ private function extractCallable(Route $route)
return $controller;
} catch (\InvalidArgumentException $e) {
}

return null;
}
}
Expand Up @@ -149,5 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

return 1;
}

return null;
}
}
Expand Up @@ -242,7 +242,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!\count($operation->getDomains())) {
$errorIo->warning('No translation messages were found.');

return;
return null;
}

$resultMessage = 'Translation files were successfully updated';
Expand Down Expand Up @@ -307,6 +307,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$errorIo->success($resultMessage.'.');

return null;
}

private function filterCatalogue(MessageCatalogue $catalogue, $domain)
Expand Down

0 comments on commit 8069b58

Please sign in to comment.