Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

More return type fixes (bis) #42490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(ManagerRegistry $registry)
/**
* This cache warmer is not optional, without proxies fatal error occurs!
*
* @return false
* @return bool
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is not allowed as a standalone type

Copy link
Member

@wouterj wouterj Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is allowed as a PHPdoc type: https://docs.phpdoc.org/3.0/guide/references/phpdoc/types.html

And also recognized by static analysis tools as such. Should we keep @return false and detect this as : bool in the class loader? (feel free to ignore if you think it's not worth the effort)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is allowed, but just not as a standalone type: it should always be part of a union

*/
public function isOptional()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Uid\Factory\UuidFactory;
use Symfony\Component\Uid\NilUuid;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\UuidV4;
use Symfony\Component\Uid\UuidV6;
Expand All @@ -35,7 +34,7 @@ public function testUuidCanBeGenerated()

public function testCustomUuidfactory()
{
$uuid = new NilUuid();
$uuid = new UuidV4();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @fancyweb FYI, this test was breaking the contracts

$em = new EntityManager();
$factory = $this->createMock(UuidFactory::class);
$factory->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function warmUp(string $cacheDir)
spl_autoload_register([ClassExistenceResource::class, 'throwOnRequiredClass']);
try {
if (!$this->doWarmUp($cacheDir, $arrayAdapter)) {
return;
return [];
}
} finally {
spl_autoload_unregister([ClassExistenceResource::class, 'throwOnRequiredClass']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testWarmUpWithWarmebleInterface()
$routerCacheWarmer = new RouterCacheWarmer($containerMock);

$routerCacheWarmer->warmUp('/tmp');
$routerMock->expects($this->any())->method('warmUp')->with('/tmp')->willReturn('');
$routerMock->expects($this->any())->method('warmUp')->with('/tmp')->willReturn([]);
$this->addToAssertionCount(1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function warmUp(string $cacheDir)
{
// skip warmUp when translator doesn't use cache
if (null === $this->options['cache_dir']) {
return;
return [];
}

$localesToWarmUp = $this->enabledLocales ?: array_merge($this->getFallbackLocales(), [$this->getLocale()], $this->resourceLocales);
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function init($redis, string $namespace, int $defaultLifetime, ?Marshall
*
* @param array $options See self::$defaultConnectionOptions
*
* @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option
* @return \Redis|\RedisArray|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option
*
* @throws InvalidArgumentException when the DSN is invalid
*/
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/HelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setHelperSet(HelperSet $helperSet = null);
/**
* Gets the helper set associated with this helper.
*
* @return HelperSet A HelperSet instance
* @return HelperSet|null
*/
public function getHelperSet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function configure()
$this->setName('foo:lock2');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$this->lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function configure()
$this->setName('foo:lock');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
if (!$this->lock()) {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('execute called');

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ public function setConfigurator($configurator)
/**
* Gets the configurator to call after the service is fully initialized.
*
* @return callable|array|null
* @return string|array|null
*/
public function getConfigurator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(ContainerBuilder $container, string $env = null)
*/
public function load($resource, string $type = null)
{
$resource($this->container, $this->env);
return $resource($this->container, $this->env);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function load($file, string $type = null)
$this->import($dir, null, false, $path);
}
}

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function import($resource, string $type = null, $ignoreErrors = false, st
}

try {
parent::import(...$args);
return parent::import(...$args);
} catch (LoaderLoadException $e) {
if (!$ignoreNotFound || !($prev = $e->getPrevious()) instanceof FileLocatorFileNotFoundException) {
throw $e;
Expand All @@ -79,6 +79,8 @@ public function import($resource, string $type = null, $ignoreErrors = false, st
throw $e;
}
}

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function load($resource, string $type = null)
}

$this->container->addResource($globResource);

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function load($resource, string $type = null)
$this->container->setParameter($key, $this->phpize($value));
}
}

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function load($resource, string $type = null)
$this->instanceof = [];
$this->registerAliasesForSinglyImplementedInterfaces();
}

return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function load($resource, string $type = null)
}
}
}

return null;
}

private function loadXml(\DOMDocument $xml, string $path, \DOMNode $root = null): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function load($resource, string $type = null)

// empty file
if (null === $content) {
return;
return null;
}

$this->loadContent($content, $path);
Expand All @@ -145,6 +145,8 @@ public function load($resource, string $type = null)
$this->env = $env;
}
}

return null;
}

private function loadContent(array $content, string $path)
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/DomCrawler/Field/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getName()
/**
* Gets the value of the field.
*
* @return string|array The value of the field
* @return string|array|null
*/
public function getValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function transform($value)
*
* @param string $value Percentage value
*
* @return int|float Normalized value
* @return int|float|null
*
* @throws TransformationFailedException if the given value is not a string or
* if the value could not be transformed
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public function getScheme()
*
* The "X-Forwarded-Port" header must contain the client port.
*
* @return int|string can be a string if fetched from the server bag
* @return int|string|null Can be a string if fetched from the server bag
*/
public function getPort()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function getLastUsed()
public function clear()
{
// nothing to do
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\VarDumper\Cloner\Data;

/**
* @author Fabien Potencier <fabien@symfony.com>
Expand Down Expand Up @@ -343,8 +344,8 @@ public function getRouteParams()
/**
* Gets the parsed controller.
*
* @return array|string The controller as a string or array of data
* with keys 'class', 'method', 'file' and 'line'
* @return array|string|Data The controller as a string or array of data
* with keys 'class', 'method', 'file' and 'line'
*/
public function getController()
{
Expand All @@ -354,8 +355,8 @@ public function getController()
/**
* Gets the previous request attributes.
*
* @return array|bool A legacy array of data from the previous redirection response
* or false otherwise
* @return array|Data|false A legacy array of data from the previous redirection response
* or false otherwise
*/
public function getRedirect()
{
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpKernel/Profiler/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setParent(self $parent)
/**
* Returns the parent profile.
*
* @return self
* @return self|null
*/
public function getParent()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
Expand Down Expand Up @@ -268,6 +269,8 @@ public function testItCollectsTheSessionTraceProperly()
$session = $this->createMock(SessionInterface::class);
$session->method('getMetadataBag')->willReturnCallback(static function () use ($collector) {
$collector->collectSessionUsage();

return new MetadataBag();
});
$session->getMetadataBag();

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpKernel/Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public function getNamespace(): string
}

/**
* @return false
* @return string|false
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved
*/
public function getXsdValidationBasePath()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ public function testBindFailureShouldThrowAnException()

public function testQueryForDn()
{
$collection = new \ArrayIterator([new Entry('')]);
$collection = new class([new Entry('')]) extends \ArrayObject implements CollectionInterface {
public function toArray(): array
{
return $this->getArrayCopy();
}
};

$query = $this->createMock(QueryInterface::class);
$query->expects($this->once())->method('execute')->willReturn($collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public function __construct(ServiceProviderInterface $functions)
*/
public function getFunctions()
{
$functions = [];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpressionFunctionProviderInterface mandates an array


foreach ($this->functions->getProvidedServices() as $function => $type) {
yield new ExpressionFunction(
$functions[] = new ExpressionFunction(
$function,
static function (...$args) use ($function) {
return sprintf('($context->getParameter(\'_functions\')->get(%s)(%s))', var_export($function, true), implode(', ', $args));
Expand All @@ -45,6 +47,8 @@ function ($values, ...$args) use ($function) {
}
);
}

return $functions;
}

public function get(string $function): callable
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Runtime/Tests/phpt/kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(string $var)
$this->var = $var;
}

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response
{
return new Response('OK Kernel '.$this->var);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface
/**
* Shortcut to create a PostAuthenticationToken for you, if you don't really
* care about which authenticated token you're using.
*
* @return PostAuthenticationToken
Copy link
Member Author

@nicolas-grekas nicolas-grekas Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractAuthenticator cannot force child classes to return an instance of PostAuthenticationToken.

FormLoginAuthenticator doesn't btw.

*/
public function createToken(Passport $passport, string $firewallName): TokenInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ trait PassportTrait
{
private $badges = [];

/**
* @return $this
*/
public function addBadge(BadgeInterface $badge): PassportInterface
{
$this->badges[\get_class($badge)] = $badge;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.