minor #41943 [4.4] Backport type fixes (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[4.4] Backport type fixes

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

And other changes made while preparing 6.0.

Commits
-------

e1afcb6de1 Backport type fixes
This commit is contained in:
Nicolas Grekas 2021-07-02 17:08:37 +02:00
commit cf0f3c9834
81 changed files with 126 additions and 271 deletions

View File

@ -67,11 +67,8 @@ class ControllerResolver extends ContainerControllerResolver
*/
protected function instantiateController($class)
{
return $this->configureController(parent::instantiateController($class), $class);
}
$controller = parent::instantiateController($class);
private function configureController($controller, string $class)
{
if ($controller instanceof ContainerAwareInterface) {
$controller->setContainer($this->container);
}

View File

@ -16,8 +16,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\DataCollector\RouterDataCollector as BaseRouterDataCollector;
/**
* RouterDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4

View File

@ -25,7 +25,7 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader
/**
* Configures the _controller default parameter of a given Route instance.
*
* @param mixed $annot The annotation class instance
* @param object $annot The annotation class instance
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
{

View File

@ -20,8 +20,6 @@ use Symfony\Component\Translation\Formatter\MessageFormatterInterface;
use Symfony\Component\Translation\Translator as BaseTranslator;
/**
* Translator.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Translator extends BaseTranslator implements WarmableInterface

View File

@ -42,9 +42,6 @@ class ClassExistenceResource implements SelfCheckingResourceInterface
}
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->resource;

View File

@ -35,9 +35,6 @@ class ComposerResource implements SelfCheckingResourceInterface
return array_keys($this->vendors);
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return __CLASS__;

View File

@ -39,9 +39,6 @@ class DirectoryResource implements SelfCheckingResourceInterface
}
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return md5(serialize([$this->resource, $this->pattern]));

View File

@ -36,9 +36,6 @@ class FileExistenceResource implements SelfCheckingResourceInterface
$this->exists = file_exists($resource);
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->resource;

View File

@ -41,9 +41,6 @@ class FileResource implements SelfCheckingResourceInterface
}
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return $this->resource;

View File

@ -60,9 +60,6 @@ class GlobResource implements \IteratorAggregate, SelfCheckingResourceInterface
return $this->prefix;
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return 'glob.'.$this->prefix.(int) $this->recursive.$this->pattern.(int) $this->forExclusion.implode("\0", $this->excludedPrefixes);

View File

@ -26,8 +26,6 @@ interface ResourceInterface
* to be identical for different ResourceInterface instances referring to the same
* resource; and it should be unlikely to collide with that of other, unrelated
* resource instances.
*
* @return string A string representation unique to the underlying Resource
*/
public function __toString();
}

View File

@ -222,8 +222,6 @@ class ExprBuilderTest extends TestCase
*
* @param array|null $config The config you want to use for the finalization, if nothing provided
* a simple ['key'=>'value'] will be used
*
* @return array The finalized config values
*/
protected function finalizeTestBuilder(NodeDefinition $nodeDefinition, array $config = null): array
{
@ -254,7 +252,7 @@ class ExprBuilderTest extends TestCase
* @param mixed $value The value to test
* @param mixed $config The config values that new to be finalized
*/
protected function assertFinalizedValueIs($value, NodeDefinition $nodeDefinition, $config = null)
protected function assertFinalizedValueIs($value, NodeDefinition $nodeDefinition, $config = null): void
{
$this->assertEquals(['key' => $value], $this->finalizeTestBuilder($nodeDefinition, $config));
}

View File

@ -375,10 +375,10 @@ class Command
/**
* Adds an argument.
*
* @param string $name The argument name
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
* @param string $description A description text
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
* @param string $name The argument name
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (for InputArgument::OPTIONAL mode only)
*
* @throws InvalidArgumentException When argument mode is not valid
*
@ -394,11 +394,11 @@ class Command
/**
* Adds an option.
*
* @param string $name The option name
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param string|string[]|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
* @param string $name The option name
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for InputOption::VALUE_NONE)
*
* @throws InvalidArgumentException If option mode is invalid or incompatible
*

View File

@ -585,11 +585,11 @@ class Table
return new TableRows(function () use ($rows, $unmergedRows): \Traversable {
foreach ($rows as $rowKey => $row) {
yield $this->fillCells($row);
yield $row instanceof TableSeparator ? $row : $this->fillCells($row);
if (isset($unmergedRows[$rowKey])) {
foreach ($unmergedRows[$rowKey] as $unmergedRow) {
yield $this->fillCells($unmergedRow);
foreach ($unmergedRows[$rowKey] as $row) {
yield $row instanceof TableSeparator ? $row : $this->fillCells($row);
}
}
}
@ -670,7 +670,7 @@ class Table
/**
* fill cells for a row that contains colspan > 1.
*/
private function fillCells($row)
private function fillCells(iterable $row)
{
$newRow = [];

View File

@ -31,10 +31,10 @@ class InputArgument
private $description;
/**
* @param string $name The argument name
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param string|string[]|null $default The default value (for self::OPTIONAL mode only)
* @param string $name The argument name
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (for self::OPTIONAL mode only)
*
* @throws InvalidArgumentException When argument mode is not valid
*/
@ -86,7 +86,7 @@ class InputArgument
/**
* Sets the default value.
*
* @param string|string[]|null $default The default value
* @param mixed $default The default value
*
* @throws LogicException When incorrect default value is given
*/
@ -110,7 +110,7 @@ class InputArgument
/**
* Returns the default value.
*
* @return string|string[]|null The default value
* @return mixed
*/
public function getDefault()
{

View File

@ -85,7 +85,7 @@ interface InputInterface
*
* @param string $name The argument name
*
* @return string|string[]|null The argument value
* @return mixed
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
@ -94,8 +94,8 @@ interface InputInterface
/**
* Sets an argument value by name.
*
* @param string $name The argument name
* @param string|string[]|null $value The argument value
* @param string $name The argument name
* @param mixed $value The argument value
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
@ -122,7 +122,7 @@ interface InputInterface
*
* @param string $name The option name
*
* @return string|string[]|bool|null The option value
* @return mixed
*
* @throws InvalidArgumentException When option given doesn't exist
*/
@ -131,8 +131,8 @@ interface InputInterface
/**
* Sets an option value by name.
*
* @param string $name The option name
* @param string|string[]|bool|null $value The option value
* @param string $name The option name
* @param mixed $value The option value
*
* @throws InvalidArgumentException When option given doesn't exist
*/

View File

@ -48,11 +48,11 @@ class InputOption
private $description;
/**
* @param string $name The option name
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the VALUE_* constants
* @param string $description A description text
* @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
* @param string $name The option name
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::VALUE_NONE)
*
* @throws InvalidArgumentException If option mode is invalid or incompatible
*/
@ -164,7 +164,7 @@ class InputOption
/**
* Sets the default value.
*
* @param string|string[]|bool|null $default The default value
* @param mixed $default The default value
*
* @throws LogicException When incorrect default value is given
*/
@ -188,7 +188,7 @@ class InputOption
/**
* Returns the default value.
*
* @return string|string[]|bool|null The default value
* @return mixed
*/
public function getDefault()
{

View File

@ -163,7 +163,7 @@ abstract class Output implements OutputInterface
break;
}
$this->doWrite($message, $newline);
$this->doWrite($message ?? '', $newline);
}
}

View File

@ -71,9 +71,6 @@ class AttributeNode extends AbstractNode
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
$attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;

View File

@ -50,9 +50,6 @@ class ClassNode extends AbstractNode
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
return sprintf('%s[%s.%s]', $this->getNodeName(), $this->selector, $this->name);

View File

@ -57,9 +57,6 @@ class CombinedSelectorNode extends AbstractNode
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
$combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;

View File

@ -50,9 +50,6 @@ class ElementNode extends AbstractNode
return new Specificity(0, 0, $this->element ? 1 : 0);
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
$element = $this->element ?: '*';

View File

@ -65,9 +65,6 @@ class FunctionNode extends AbstractNode
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
$arguments = implode(', ', array_map(function (Token $token) {

View File

@ -50,9 +50,6 @@ class HashNode extends AbstractNode
return $this->selector->getSpecificity()->plus(new Specificity(1, 0, 0));
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
return sprintf('%s[%s#%s]', $this->getNodeName(), $this->selector, $this->id);

View File

@ -50,9 +50,6 @@ class NegationNode extends AbstractNode
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
return sprintf('%s[%s:not(%s)]', $this->getNodeName(), $this->selector, $this->subSelector);

View File

@ -50,9 +50,6 @@ class PseudoNode extends AbstractNode
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
return sprintf('%s[%s:%s]', $this->getNodeName(), $this->selector, $this->identifier);

View File

@ -50,9 +50,6 @@ class SelectorNode extends AbstractNode
return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));
}
/**
* {@inheritdoc}
*/
public function __toString(): string
{
return sprintf('%s[%s%s]', $this->getNodeName(), $this->tree, $this->pseudoElement ? '::'.$this->pseudoElement : '');

View File

@ -374,7 +374,7 @@ class AutowirePass extends AbstractRecursivePass
$this->ambiguousServiceTypes[$type][] = $id;
}
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): callable
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): \Closure
{
if (null === $this->typesClone->container) {
$this->typesClone->container = new ContainerBuilder($this->container->getParameterBag());

View File

@ -32,9 +32,6 @@ class ContainerParametersResource implements ResourceInterface
$this->parameters = $parameters;
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return 'container_parameters_'.md5(serialize($this->parameters));

View File

@ -109,7 +109,7 @@ class Container implements ResettableContainerInterface
*
* @param string $name The parameter name
*
* @return array|bool|float|int|string|null The parameter value
* @return mixed
*
* @throws InvalidArgumentException if the parameter is not defined
*/

View File

@ -883,8 +883,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
}
/**
* Gets all defined aliases.
*
* @return Alias[] An array of aliases
*/
public function getAliases()

View File

@ -54,8 +54,6 @@ interface ContainerInterface extends PsrContainerInterface
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
/**
* Returns true if the given service is defined.
*
* @param string $id The service identifier
*
* @return bool true if the service is defined, false otherwise
@ -76,7 +74,7 @@ interface ContainerInterface extends PsrContainerInterface
*
* @param string $name The parameter name
*
* @return array|bool|float|int|string|null The parameter value
* @return mixed The parameter value
*
* @throws InvalidArgumentException if the parameter is not defined
*/

View File

@ -805,7 +805,7 @@ class Definition
/**
* Sets a configurator to call after the service is fully initialized.
*
* @param string|array|Reference $configurator A PHP function, reference or an array containing a class/Reference and a method to call
* @param string|array|Reference|null $configurator A PHP function, reference or an array containing a class/Reference and a method to call
*
* @return $this
*/

View File

@ -47,7 +47,7 @@ class ServiceConfigurator extends AbstractServiceConfigurator
private $allowParent;
private $path;
public function __construct(ContainerBuilder $container, array $instanceof, bool $allowParent, ServicesConfigurator $parent, Definition $definition, $id, array $defaultTags, string $path = null)
public function __construct(ContainerBuilder $container, array $instanceof, bool $allowParent, ServicesConfigurator $parent, Definition $definition, ?string $id, array $defaultTags, string $path = null)
{
$this->container = $container;
$this->instanceof = $instanceof;

View File

@ -850,9 +850,6 @@ class YamlFileLoader extends FileLoader
return $value;
}
/**
* Loads from Extensions.
*/
private function loadFromExtensions(array $content)
{
foreach ($content as $namespace => $values) {
@ -868,9 +865,6 @@ class YamlFileLoader extends FileLoader
}
}
/**
* Checks the keywords used to define a service.
*/
private function checkDefinition(string $id, array $definition, string $file)
{
if ($this->isLoadingInstanceof) {

View File

@ -35,6 +35,8 @@ class ContainerBag extends FrozenParameterBag implements ContainerBagInterface
/**
* {@inheritdoc}
*
* @return mixed
*/
public function get($name)
{
@ -43,6 +45,8 @@ class ContainerBag extends FrozenParameterBag implements ContainerBagInterface
/**
* {@inheritdoc}
*
* @return bool
*/
public function has($name)
{

View File

@ -25,16 +25,13 @@ class ParameterBag implements ParameterBagInterface
protected $parameters = [];
protected $resolved = false;
/**
* @param array $parameters An array of parameters
*/
public function __construct(array $parameters = [])
{
$this->add($parameters);
}
/**
* Clears all parameters.
* {@inheritdoc}
*/
public function clear()
{
@ -42,9 +39,7 @@ class ParameterBag implements ParameterBagInterface
}
/**
* Adds parameters to the service container parameters.
*
* @param array $parameters An array of parameters
* {@inheritdoc}
*/
public function add(array $parameters)
{
@ -104,10 +99,7 @@ class ParameterBag implements ParameterBagInterface
}
/**
* Sets a service container parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
* {@inheritdoc}
*/
public function set($name, $value)
{
@ -123,9 +115,7 @@ class ParameterBag implements ParameterBagInterface
}
/**
* Removes a parameter.
*
* @param string $name The parameter name
* {@inheritdoc}
*/
public function remove($name)
{

View File

@ -31,8 +31,6 @@ interface ParameterBagInterface
/**
* Adds parameters to the service container parameters.
*
* @param array $parameters An array of parameters
*
* @throws LogicException if the parameter can not be added
*/
public function add(array $parameters);

View File

@ -250,7 +250,7 @@ class ResolveChildDefinitionsPassTest extends TestCase
$container->register('parent', 'parentClass');
$container->register('sibling', 'siblingClass')
->setConfigurator(new ChildDefinition('parent'), 'foo')
->setConfigurator([new ChildDefinition('parent'), 'foo'])
->setFactory([new ChildDefinition('parent'), 'foo'])
->addArgument(new ChildDefinition('parent'))
->setProperty('prop', new ChildDefinition('parent'))
@ -260,8 +260,8 @@ class ResolveChildDefinitionsPassTest extends TestCase
$this->process($container);
$configurator = $container->getDefinition('sibling')->getConfigurator();
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($configurator));
$this->assertSame('parentClass', $configurator->getClass());
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($configurator[0]));
$this->assertSame('parentClass', $configurator[0]->getClass());
$factory = $container->getDefinition('sibling')->getFactory();
$this->assertSame('Symfony\Component\DependencyInjection\Definition', \get_class($factory[0]));

View File

@ -196,7 +196,7 @@ class ErrorHandler
* Sets a logger to non assigned errors levels.
*
* @param LoggerInterface $logger A PSR-3 logger to put as default for the given levels
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
* @param array|int|null $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
* @param bool $replace Whether to replace or not any existing logger
*/
public function setDefaultLogger(LoggerInterface $logger, $levels = \E_ALL, bool $replace = false): void

View File

@ -62,11 +62,17 @@ class FlattenException extends LegacyFlattenException
/** @var string|null */
private $asString;
/**
* @return static
*/
public static function create(\Exception $exception, $statusCode = null, array $headers = []): self
{
return static::createFromThrowable($exception, $statusCode, $headers);
}
/**
* @return static
*/
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []): self
{
$e = new static();

View File

@ -476,6 +476,10 @@ class TestEventListener
$e->stopPropagation();
}
}
public function __invoke()
{
}
}
class TestWithDispatcher

View File

@ -761,7 +761,7 @@ class Filesystem
/**
* @internal
*/
public static function handleError($type, $msg)
public static function handleError(int $type, string $msg)
{
self::$lastError = $msg;
}

View File

@ -33,7 +33,7 @@ class MockStream
/**
* @param string $path The file path or URL to stat
* @param array $flags Holds additional flags set by the streams API
* @param int $flags Holds additional flags set by the streams API
*
* @return array File stats
*/

View File

@ -30,8 +30,7 @@ class SortableIterator implements \IteratorAggregate
private $sort;
/**
* @param \Traversable $iterator The Iterator to filter
* @param int|callable $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
* @param int|callable $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
*
* @throws \InvalidArgumentException
*/

View File

@ -18,7 +18,7 @@ class SortableIteratorTest extends RealIteratorTestCase
public function testConstructor()
{
try {
new SortableIterator(new Iterator([]), 'foobar');
new SortableIterator(new Iterator([]), -255);
$this->fail('__construct() throws an \InvalidArgumentException exception if the mode is not valid');
} catch (\Exception $e) {
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '__construct() throws an \InvalidArgumentException exception if the mode is not valid');

View File

@ -316,7 +316,7 @@ final class CurlResponse implements ResponseInterface
/**
* Parses header lines as curl yields them to us.
*/
private static function parseHeaderLine($ch, string $data, array &$info, array &$headers, ?array $options, CurlClientState $multi, int $id, ?string &$location, ?callable $resolveRedirect, ?LoggerInterface $logger, &$content = null): int
private static function parseHeaderLine($ch, string $data, array &$info, array &$headers, ?array $options, CurlClientState $multi, int $id, ?string &$location, ?callable $resolveRedirect, ?LoggerInterface $logger): int
{
$waitFor = @curl_getinfo($ch, \CURLINFO_PRIVATE) ?: '_0';

View File

@ -254,7 +254,7 @@ class UploadedFile extends File
*
* @return int|float Returns float if size > PHP_INT_MAX
*/
private static function parseFilesize($size)
private static function parseFilesize(string $size)
{
if ('' === $size) {
return 0;

View File

@ -75,22 +75,20 @@ class FileBag extends ParameterBag
return $file;
}
if (\is_array($file)) {
$file = $this->fixPhpFilesArray($file);
$keys = array_keys($file);
sort($keys);
$file = $this->fixPhpFilesArray($file);
$keys = array_keys($file);
sort($keys);
if (self::FILE_KEYS == $keys) {
if (\UPLOAD_ERR_NO_FILE == $file['error']) {
$file = null;
} else {
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['error'], false);
}
if (self::FILE_KEYS == $keys) {
if (\UPLOAD_ERR_NO_FILE == $file['error']) {
$file = null;
} else {
$file = array_map([$this, 'convertFileInformation'], $file);
if (array_keys($keys) === $keys) {
$file = array_filter($file);
}
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['error'], false);
}
} else {
$file = array_map(function ($v) { return $v instanceof UploadedFile || \is_array($v) ? $this->convertFileInformation($v) : $v; }, $file);
if (array_keys($keys) === $keys) {
$file = array_filter($file);
}
}

View File

@ -133,9 +133,9 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Sets a header by name.
*
* @param string $key The key
* @param string|string[] $values The value or an array of values
* @param bool $replace Whether to replace the actual value or not (true by default)
* @param string $key The key
* @param string|string[]|null $values The value or an array of values
* @param bool $replace Whether to replace the actual value or not (true by default)
*/
public function set($key, $values, $replace = true)
{
@ -228,8 +228,8 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Adds a custom Cache-Control directive.
*
* @param string $key The Cache-Control directive name
* @param mixed $value The Cache-Control directive value
* @param string $key The Cache-Control directive name
* @param bool|string $value The Cache-Control directive value
*/
public function addCacheControlDirective($key, $value = true)
{
@ -255,11 +255,11 @@ class HeaderBag implements \IteratorAggregate, \Countable
*
* @param string $key The directive name
*
* @return mixed The directive value if defined, null otherwise
* @return bool|string|null The directive value if defined, null otherwise
*/
public function getCacheControlDirective($key)
{
return \array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
return $this->cacheControl[$key] ?? null;
}
/**

View File

@ -257,7 +257,7 @@ class JsonResponseTest extends TestCase
public function testConstructorWithObjectWithToStringMethod()
{
$class = new class() {
public function __toString()
public function __toString(): string
{
return '{}';
}

View File

@ -122,7 +122,7 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
$lowTtl = 10;
$this->redisClient->setex(self::PREFIX.'id', $lowTtl, 'foo');
$this->storage->updateTimestamp('id', []);
$this->storage->updateTimestamp('id', 'data');
$this->assertGreaterThan($lowTtl, $this->redisClient->ttl(self::PREFIX.'id'));
}

View File

@ -19,7 +19,7 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata;
interface ArgumentMetadataFactoryInterface
{
/**
* @param mixed $controller The controller to resolve the arguments for
* @param string|object|array $controller The controller to resolve the arguments for
*
* @return ArgumentMetadata[]
*/

View File

@ -18,8 +18,6 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
/**
* LogDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4

View File

@ -388,7 +388,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
/**
* Parse a controller.
*
* @param mixed $controller The controller to parse
* @param string|object|array|null $controller The controller to parse
*
* @return array|string An array of controller data or a simple string
*/

View File

@ -32,7 +32,7 @@ class FileLinkFormatter
/**
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
*/
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
{
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {

View File

@ -13,35 +13,35 @@ define('LINE_WIDTH', 75);
define('LINE', str_repeat('-', LINE_WIDTH)."\n");
function bailout($message)
function bailout(string $message)
{
echo wordwrap($message, LINE_WIDTH)." Aborting.\n";
exit(1);
}
function strip_minor_versions($version)
function strip_minor_versions(string $version)
{
preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches);
return $matches['version'];
}
function centered($text)
function centered(string $text)
{
$padding = (int) ((LINE_WIDTH - strlen($text)) / 2);
return str_repeat(' ', $padding).$text;
}
function cd($dir)
function cd(string $dir)
{
if (false === chdir($dir)) {
bailout("Could not switch to directory $dir.");
}
}
function run($command)
function run(string $command)
{
exec($command, $output, $status);
@ -53,7 +53,7 @@ function run($command)
}
}
function get_icu_version_from_genrb($genrb)
function get_icu_version_from_genrb(string $genrb)
{
exec($genrb.' --version - 2>&1', $output, $status);
@ -70,7 +70,7 @@ function get_icu_version_from_genrb($genrb)
error_reporting(\E_ALL);
set_error_handler(function ($type, $msg, $file, $line) {
set_error_handler(function (int $type, string $msg, string $file, int $line) {
throw new \ErrorException($msg, 0, $type, $file, $line);
});

View File

@ -81,7 +81,7 @@ class PhpSerializer implements SerializerInterface
/**
* @internal
*/
public static function handleUnserializeCallback($class)
public static function handleUnserializeCallback(string $class)
{
throw new MessageDecodingFailedException(sprintf('Message class "%s" not found during decoding.', $class));
}

View File

@ -229,7 +229,7 @@ final class Headers
/**
* @internal
*/
public function getHeaderBody($name)
public function getHeaderBody(string $name)
{
return $this->has($name) ? $this->get($name)->getBody() : null;
}
@ -266,7 +266,7 @@ final class Headers
/**
* @internal
*/
public function setHeaderParameter(string $name, string $parameter, $value): void
public function setHeaderParameter(string $name, string $parameter, ?string $value): void
{
if (!$this->has($name)) {
throw new LogicException(sprintf('Unable to set parameter "%s" on header "%s" as the header is not defined.', $parameter, $name));

View File

@ -26,8 +26,6 @@ interface MimeTypeGuesserInterface
/**
* Guesses the MIME type of the file with the given path.
*
* @param string $path The path to the file
*
* @return string|null The MIME type or null, if none could be guessed
*
* @throws \LogicException If the guesser is not supported

View File

@ -39,8 +39,10 @@ class DataPart extends TextPart
parent::__construct($body, null, $subtype, $encoding);
$this->filename = $filename;
$this->setName($filename);
if (null !== $filename) {
$this->filename = $filename;
$this->setName($filename);
}
$this->setDisposition('attachment');
}

View File

@ -232,10 +232,6 @@ class OptionsResolver implements Options
}
/**
* Sets a list of default values.
*
* @param array $defaults The default values to set
*
* @return $this
*
* @throws AccessException If called from a lazy option or normalizer
@ -468,8 +464,7 @@ class OptionsResolver implements Options
*
* The resolved option value is set to the return value of the closure.
*
* @param string $option The option name
* @param \Closure $normalizer The normalizer
* @param string $option The option name
*
* @return $this
*
@ -512,10 +507,6 @@ class OptionsResolver implements Options
*
* The resolved option value is set to the return value of the closure.
*
* @param string $option The option name
* @param \Closure $normalizer The normalizer
* @param bool $forcePrepend If set to true, prepend instead of appending
*
* @return $this
*
* @throws UndefinedOptionsException If the option is undefined
@ -767,8 +758,6 @@ class OptionsResolver implements Options
* - Options have invalid types;
* - Options have invalid values.
*
* @param array $options A map of option names to values
*
* @return array The merged and validated options
*
* @throws UndefinedOptionsException If an option name is undefined

View File

@ -171,7 +171,7 @@ abstract class AbstractPipes implements PipesInterface
/**
* @internal
*/
public function handleError($type, $msg)
public function handleError(int $type, string $msg)
{
$this->lastError = $msg;
}

View File

@ -26,9 +26,6 @@ class AnnotationFileLoader extends FileLoader
{
protected $loader;
/**
* @throws \RuntimeException
*/
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
{
if (!\function_exists('token_get_all')) {

View File

@ -32,7 +32,7 @@ class ContainerLoader extends ObjectLoader
*/
public function supports($resource, $type = null)
{
return 'service' === $type;
return 'service' === $type && \is_string($resource);
}
/**

View File

@ -195,7 +195,7 @@ class StaticPrefixCollection
return [substr($prefix, 0, $i), substr($prefix, 0, $staticLength ?? $i)];
}
public static function handleError($type, $msg)
public static function handleError(int $type, string $msg)
{
return false !== strpos($msg, 'Compilation failed: lookbehind assertion is not fixed length');
}

View File

@ -116,8 +116,6 @@ class Route implements \Serializable
}
/**
* Returns the pattern for the path.
*
* @return string The path pattern
*/
public function getPath()
@ -128,8 +126,6 @@ class Route implements \Serializable
/**
* Sets the pattern for the path.
*
* This method implements a fluent interface.
*
* @param string $pattern The path pattern
*
* @return $this
@ -158,8 +154,6 @@ class Route implements \Serializable
}
/**
* Returns the pattern for the host.
*
* @return string The host pattern
*/
public function getHost()
@ -170,8 +164,6 @@ class Route implements \Serializable
/**
* Sets the pattern for the host.
*
* This method implements a fluent interface.
*
* @param string $pattern The host pattern
*
* @return $this
@ -199,8 +191,6 @@ class Route implements \Serializable
* Sets the schemes (e.g. 'https') this route is restricted to.
* So an empty array means that any scheme is allowed.
*
* This method implements a fluent interface.
*
* @param string|string[] $schemes The scheme or an array of schemes
*
* @return $this
@ -240,8 +230,6 @@ class Route implements \Serializable
* Sets the HTTP methods (e.g. 'POST') this route is restricted to.
* So an empty array means that any method is allowed.
*
* This method implements a fluent interface.
*
* @param string|string[] $methods The method or an array of methods
*
* @return $this
@ -255,8 +243,6 @@ class Route implements \Serializable
}
/**
* Returns the options.
*
* @return array The options
*/
public function getOptions()
@ -265,10 +251,6 @@ class Route implements \Serializable
}
/**
* Sets the options.
*
* This method implements a fluent interface.
*
* @return $this
*/
public function setOptions(array $options)
@ -281,10 +263,6 @@ class Route implements \Serializable
}
/**
* Adds options.
*
* This method implements a fluent interface.
*
* @return $this
*/
public function addOptions(array $options)
@ -300,8 +278,6 @@ class Route implements \Serializable
/**
* Sets an option value.
*
* This method implements a fluent interface.
*
* @param string $name An option name
* @param mixed $value The option value
*
@ -340,8 +316,6 @@ class Route implements \Serializable
}
/**
* Returns the defaults.
*
* @return array The defaults
*/
public function getDefaults()
@ -350,12 +324,6 @@ class Route implements \Serializable
}
/**
* Sets the defaults.
*
* This method implements a fluent interface.
*
* @param array $defaults The defaults
*
* @return $this
*/
public function setDefaults(array $defaults)
@ -366,12 +334,6 @@ class Route implements \Serializable
}
/**
* Adds defaults.
*
* This method implements a fluent interface.
*
* @param array $defaults The defaults
*
* @return $this
*/
public function addDefaults(array $defaults)
@ -433,8 +395,6 @@ class Route implements \Serializable
}
/**
* Returns the requirements.
*
* @return array The requirements
*/
public function getRequirements()
@ -443,12 +403,6 @@ class Route implements \Serializable
}
/**
* Sets the requirements.
*
* This method implements a fluent interface.
*
* @param array $requirements The requirements
*
* @return $this
*/
public function setRequirements(array $requirements)
@ -459,12 +413,6 @@ class Route implements \Serializable
}
/**
* Adds requirements.
*
* This method implements a fluent interface.
*
* @param array $requirements The requirements
*
* @return $this
*/
public function addRequirements(array $requirements)
@ -526,8 +474,6 @@ class Route implements \Serializable
}
/**
* Returns the condition.
*
* @return string The condition
*/
public function getCondition()
@ -538,8 +484,6 @@ class Route implements \Serializable
/**
* Sets the condition.
*
* This method implements a fluent interface.
*
* @param string $condition The condition
*
* @return $this

View File

@ -45,6 +45,10 @@ class UserPasswordValidator extends ConstraintValidator
return;
}
if (!\is_string($password)) {
throw new UnexpectedTypeException($password, 'string');
}
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof UserInterface) {

View File

@ -328,7 +328,7 @@ class ContextListener extends AbstractListener implements ListenerInterface
/**
* @internal
*/
public static function handleUnserializeCallback($class)
public static function handleUnserializeCallback(string $class)
{
throw new \ErrorException('Class not found: '.$class, 0x37313bc);
}

View File

@ -29,7 +29,7 @@ class Groups
private $groups;
/**
* @throws InvalidArgumentException
* @param string[] $groups
*/
public function __construct(array $data)
{
@ -48,8 +48,6 @@ class Groups
}
/**
* Gets groups.
*
* @return string[]
*/
public function getGroups()

View File

@ -32,7 +32,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl
private $defaultContext;
private $nameConverter;
public function __construct($defaultContext = [], NameConverterInterface $nameConverter = null)
public function __construct(array $defaultContext = [], NameConverterInterface $nameConverter = null)
{
$this->defaultContext = $defaultContext;
$this->nameConverter = $nameConverter;

View File

@ -24,7 +24,7 @@ interface ExtractorInterface
/**
* Extracts translation messages from files, a file or a directory to the catalogue.
*
* @param string|array $resource Files, a file or a directory
* @param string|iterable $resource Files, a file or a directory
*/
public function extract($resource, MessageCatalogue $catalogue);

View File

@ -27,8 +27,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
private $parent;
/**
* @param string $locale The locale
* @param array $messages An array of messages classified by domain
* @param array $messages An array of messages classified by domain
*/
public function __construct(?string $locale, array $messages = [])
{

View File

@ -177,8 +177,6 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran
/**
* Sets the fallback locales.
*
* @param array $locales The fallback locales
*
* @throws InvalidArgumentException If a locale contains invalid characters
*/
public function setFallbackLocales(array $locales)

View File

@ -157,7 +157,7 @@ class RangeValidator extends ConstraintValidator
}
}
private function getLimit($propertyPath, $default, Constraint $constraint)
private function getLimit(?string $propertyPath, $default, Constraint $constraint)
{
if (null === $propertyPath) {
return $default;

View File

@ -233,8 +233,6 @@ abstract class ConstraintValidatorTestCase extends TestCase
}
/**
* @param $message
*
* @return ConstraintViolationAssertion
*/
protected function buildViolation($message)

View File

@ -23,7 +23,7 @@ class LinkStub extends ConstStub
private static $vendorRoots;
private static $composerRoots;
public function __construct($label, int $line = 0, $href = null)
public function __construct(string $label, int $line = 0, string $href = null)
{
$this->value = $label;

View File

@ -48,7 +48,7 @@ class ResourceCaster
public static function castStream($stream, array $a, Stub $stub, $isNested)
{
$a = stream_get_meta_data($stream) + static::castStreamContext($stream, $a, $stub, $isNested);
if (isset($a['uri'])) {
if ($a['uri'] ?? false) {
$a['uri'] = new LinkStub($a['uri']);
}

View File

@ -129,7 +129,7 @@ class SplCaster
}
}
if (isset($a[$prefix.'realPath'])) {
if ($a[$prefix.'realPath'] ?? false) {
$a[$prefix.'realPath'] = new LinkStub($a[$prefix.'realPath']);
}

View File

@ -998,7 +998,7 @@ EOHTML
}
}
function esc($str)
function esc(string $str)
{
return htmlspecialchars($str, \ENT_QUOTES, 'UTF-8');
}

View File

@ -78,7 +78,7 @@ class Connection
return false;
}
private static function nullErrorHandler($t, $m)
private static function nullErrorHandler(int $t, string $m)
{
// no-op
}