Skip to content

Commit

Permalink
minor #33264 [4.4] Add return types on internal|final|private methods…
Browse files Browse the repository at this point in the history
… (bis) (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[4.4] Add return types on internal|final|private methods (bis)

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Found while working on #33259

`: self` is used for final methods only. I'd have preferred using `: object` but that's not possible on PHP 7.1

Commits
-------

23faee4 [4.4] Add return types on internal|final|private methods (bis)
  • Loading branch information
nicolas-grekas committed Aug 20, 2019
2 parents 7eb5fee + 23faee4 commit 22319a9
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 83 deletions.
16 changes: 8 additions & 8 deletions src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php
Expand Up @@ -63,7 +63,7 @@ public function attach(string $file, string $name = null, string $contentType =
/**
* @return $this
*/
public function setSubject(string $subject)
public function setSubject(string $subject): self
{
$this->message->subject($subject);

Expand All @@ -78,7 +78,7 @@ public function getSubject(): ?string
/**
* @return $this
*/
public function setReturnPath(string $address)
public function setReturnPath(string $address): self
{
$this->message->returnPath($address);

Expand All @@ -93,7 +93,7 @@ public function getReturnPath(): string
/**
* @return $this
*/
public function addFrom(string $address, string $name = null)
public function addFrom(string $address, string $name = null): self
{
$this->message->addFrom($name ? new NamedAddress($address, $name) : new Address($address));

Expand All @@ -111,7 +111,7 @@ public function getFrom(): array
/**
* @return $this
*/
public function addReplyTo(string $address)
public function addReplyTo(string $address): self
{
$this->message->addReplyTo($address);

Expand All @@ -129,7 +129,7 @@ public function getReplyTo(): array
/**
* @return $this
*/
public function addTo(string $address, string $name = null)
public function addTo(string $address, string $name = null): self
{
$this->message->addTo($name ? new NamedAddress($address, $name) : new Address($address));

Expand All @@ -147,7 +147,7 @@ public function getTo(): array
/**
* @return $this
*/
public function addCc(string $address, string $name = null)
public function addCc(string $address, string $name = null): self
{
$this->message->addCc($name ? new NamedAddress($address, $name) : new Address($address));

Expand All @@ -165,7 +165,7 @@ public function getCc(): array
/**
* @return $this
*/
public function addBcc(string $address, string $name = null)
public function addBcc(string $address, string $name = null): self
{
$this->message->addBcc($name ? new NamedAddress($address, $name) : new Address($address));

Expand All @@ -183,7 +183,7 @@ public function getBcc(): array
/**
* @return $this
*/
public function setPriority(int $priority)
public function setPriority(int $priority): self
{
$this->message->setPriority($priority);

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/CacheItem.php
Expand Up @@ -67,7 +67,7 @@ public function isHit()
*
* @return $this
*/
public function set($value)
public function set($value): self
{
$this->value = $value;

Expand All @@ -79,7 +79,7 @@ public function set($value)
*
* @return $this
*/
public function expiresAt($expiration)
public function expiresAt($expiration): self
{
if (null === $expiration) {
$this->expiry = $this->defaultLifetime > 0 ? microtime(true) + $this->defaultLifetime : null;
Expand All @@ -97,7 +97,7 @@ public function expiresAt($expiration)
*
* @return $this
*/
public function expiresAfter($time)
public function expiresAfter($time): self
{
if (null === $time) {
$this->expiry = $this->defaultLifetime > 0 ? microtime(true) + $this->defaultLifetime : null;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/CssSelector/Parser/TokenStream.php
Expand Up @@ -56,7 +56,7 @@ class TokenStream
*
* @return $this
*/
public function push(Token $token)
public function push(Token $token): self
{
$this->tokens[] = $token;

Expand All @@ -68,7 +68,7 @@ public function push(Token $token)
*
* @return $this
*/
public function freeze()
public function freeze(): self
{
return $this;
}
Expand Down
Expand Up @@ -30,40 +30,38 @@ interface ExtensionInterface
*
* @return callable[]
*/
public function getNodeTranslators();
public function getNodeTranslators(): array;

/**
* Returns combination translators.
*
* @return callable[]
*/
public function getCombinationTranslators();
public function getCombinationTranslators(): array;

/**
* Returns function translators.
*
* @return callable[]
*/
public function getFunctionTranslators();
public function getFunctionTranslators(): array;

/**
* Returns pseudo-class translators.
*
* @return callable[]
*/
public function getPseudoClassTranslators();
public function getPseudoClassTranslators(): array;

/**
* Returns attribute operation translators.
*
* @return callable[]
*/
public function getAttributeMatchingTranslators();
public function getAttributeMatchingTranslators(): array;

/**
* Returns extension name.
*
* @return string
*/
public function getName();
public function getName(): string;
}
Expand Up @@ -41,7 +41,7 @@ public function __construct(int $flags = 0)
/**
* @return $this
*/
public function setFlag(int $flag, bool $on)
public function setFlag(int $flag, bool $on): self
{
if ($on && !$this->hasFlag($flag)) {
$this->flags += $flag;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
Expand Up @@ -109,15 +109,15 @@ public function replaceArgument($index, $value)
/**
* @internal
*/
public function setAutoconfigured($autoconfigured)
public function setAutoconfigured($autoconfigured): self
{
throw new BadMethodCallException('A ChildDefinition cannot be autoconfigured.');
}

/**
* @internal
*/
public function setInstanceofConditionals(array $instanceof)
public function setInstanceofConditionals(array $instanceof): self
{
throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.');
}
Expand Down
Expand Up @@ -137,7 +137,7 @@ public function freezeAfterProcessing(Extension $extension, ContainerBuilder $co
/**
* {@inheritdoc}
*/
public function getEnvPlaceholders()
public function getEnvPlaceholders(): array
{
return null !== $this->processedEnvPlaceholders ? $this->processedEnvPlaceholders : parent::getEnvPlaceholders();
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public function __construct(ExtensionInterface $extension, ParameterBagInterface
/**
* {@inheritdoc}
*/
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0): self
{
throw new LogicException(sprintf('You cannot add compiler pass "%s" from extension "%s". Compiler passes must be registered before the container is compiled.', \get_class($pass), $this->extensionClass));
}
Expand Down
Expand Up @@ -42,7 +42,7 @@ public function __construct(ServicesConfigurator $parent, Definition $definition
*
* @throws InvalidArgumentException when an invalid tag name or attribute is provided
*/
final public function tag(string $name, array $attributes = [])
final public function tag(string $name, array $attributes = []): self
{
if ('' === $name) {
throw new InvalidArgumentException('The tag name in "_defaults" must be a non-empty string.');
Expand Down
Expand Up @@ -32,7 +32,7 @@ public function __construct(ContainerBuilder $container)
*
* @return $this
*/
final public function set(string $name, $value)
final public function set(string $name, $value): self
{
$this->container->setParameter($name, static::processValue($value, true));

Expand All @@ -44,7 +44,7 @@ final public function set(string $name, $value)
*
* @return $this
*/
final public function __invoke(string $name, $value)
final public function __invoke(string $name, $value): self
{
return $this->set($name, $value);
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public function __construct(string $id)
/**
* @return $this
*/
final public function ignoreOnInvalid()
final public function ignoreOnInvalid(): self
{
$this->invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;

Expand All @@ -42,7 +42,7 @@ final public function ignoreOnInvalid()
/**
* @return $this
*/
final public function nullOnInvalid()
final public function nullOnInvalid(): self
{
$this->invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;

Expand All @@ -52,7 +52,7 @@ final public function nullOnInvalid()
/**
* @return $this
*/
final public function ignoreOnUninitialized()
final public function ignoreOnUninitialized(): self
{
$this->invalidBehavior = ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE;

Expand Down
Expand Up @@ -7,7 +7,7 @@ final class ScalarFactory
/**
* @return string
*/
public static function getSomeValue()
public static function getSomeValue(): string
{
return 'some value';
}
Expand Down
27 changes: 21 additions & 6 deletions src/Symfony/Component/Form/Util/OptionsResolverWrapper.php
Expand Up @@ -24,7 +24,10 @@ class OptionsResolverWrapper extends OptionsResolver
{
private $undefined = [];

public function setNormalizer($option, \Closure $normalizer)
/**
* @return $this
*/
public function setNormalizer($option, \Closure $normalizer): self
{
try {
parent::setNormalizer($option, $normalizer);
Expand All @@ -35,7 +38,10 @@ public function setNormalizer($option, \Closure $normalizer)
return $this;
}

public function setAllowedValues($option, $allowedValues)
/**
* @return $this
*/
public function setAllowedValues($option, $allowedValues): self
{
try {
parent::setAllowedValues($option, $allowedValues);
Expand All @@ -46,7 +52,10 @@ public function setAllowedValues($option, $allowedValues)
return $this;
}

public function addAllowedValues($option, $allowedValues)
/**
* @return $this
*/
public function addAllowedValues($option, $allowedValues): self
{
try {
parent::addAllowedValues($option, $allowedValues);
Expand All @@ -57,7 +66,10 @@ public function addAllowedValues($option, $allowedValues)
return $this;
}

public function setAllowedTypes($option, $allowedTypes)
/**
* @return $this
*/
public function setAllowedTypes($option, $allowedTypes): self
{
try {
parent::setAllowedTypes($option, $allowedTypes);
Expand All @@ -68,7 +80,10 @@ public function setAllowedTypes($option, $allowedTypes)
return $this;
}

public function addAllowedTypes($option, $allowedTypes)
/**
* @return $this
*/
public function addAllowedTypes($option, $allowedTypes): self
{
try {
parent::addAllowedTypes($option, $allowedTypes);
Expand All @@ -84,7 +99,7 @@ public function resolve(array $options = []): array
throw new AccessException('Resolve options is not supported.');
}

public function getUndefinedOptions()
public function getUndefinedOptions(): array
{
return array_keys($this->undefined);
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ public function supports(Request $request, ArgumentMetadata $argument)
/**
* {@inheritdoc}
*/
public function resolve(Request $request, ArgumentMetadata $argument)
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (\is_array($controller = $request->attributes->get('_controller'))) {
$controller = $controller[0].'::'.$controller[1];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpClientKernel.php
Expand Up @@ -39,7 +39,7 @@ public function __construct(HttpClientInterface $client = null)
$this->client = $client ?? HttpClient::create();
}

public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true): Response
{
$headers = $this->getHeaders($request);
$body = '';
Expand Down
Expand Up @@ -47,7 +47,7 @@ public function __construct(string $dsn)
/**
* {@inheritdoc}
*/
public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null)
public function find($ip, $url, $limit, $method, $start = null, $end = null, $statusCode = null): array
{
$file = $this->getIndexFilename();

Expand Down Expand Up @@ -113,7 +113,7 @@ public function purge()
/**
* {@inheritdoc}
*/
public function read($token)
public function read($token): ?Profile
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return null;
Expand All @@ -127,7 +127,7 @@ public function read($token)
*
* @throws \RuntimeException
*/
public function write(Profile $profile)
public function write(Profile $profile): bool
{
$file = $this->getFilename($profile->getToken());

Expand Down

0 comments on commit 22319a9

Please sign in to comment.