Skip to content

Commit 7eb5fee

Browse files
minor #33261 Add types to routing and DI configuration traits. (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- Add types to routing and DI configuration traits. | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | I don't think so. | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | N/A This PR backports the type declarations added to the configurator traits of the Routing and DI components. These traits expose only final methods, so it should be pretty safe to add return types to them. The only scenario I could make up where this change will break something is if a trait is used to override a method: https://3v4l.org/EAsk8 But I doubt that those traits are used that way. On master, we've used the `object` return type for the fluent methods. That type is not available on 4.4 where we have to support php 7.1. I'm using `self` instead. Since the methods are final and thus cannot be overridden, I believe that we shouldn't run into covariance issues here, so `self` should be safe. Commits ------- 1ca30c9 Add types to roting and DI configuration traits.
2 parents 543e401 + 1ca30c9 commit 7eb5fee

20 files changed

+34
-45
lines changed

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/AbstractTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait AbstractTrait
1919
*
2020
* @return $this
2121
*/
22-
final public function abstract(bool $abstract = true)
22+
final public function abstract(bool $abstract = true): self
2323
{
2424
$this->definition->setAbstract($abstract);
2525

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/ArgumentTrait.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ trait ArgumentTrait
1616
/**
1717
* Sets the arguments to pass to the service constructor/factory method.
1818
*
19-
* @param array $arguments An array of arguments
20-
*
2119
* @return $this
2220
*/
23-
final public function args(array $arguments)
21+
final public function args(array $arguments): self
2422
{
2523
$this->definition->setArguments(static::processValue($arguments, true));
2624

@@ -35,7 +33,7 @@ final public function args(array $arguments)
3533
*
3634
* @return $this
3735
*/
38-
final public function arg($key, $value)
36+
final public function arg($key, $value): self
3937
{
4038
$this->definition->setArgument($key, static::processValue($value, true));
4139

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/AutoconfigureTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trait AutoconfigureTrait
2323
*
2424
* @throws InvalidArgumentException when a parent is already set
2525
*/
26-
final public function autoconfigure(bool $autoconfigured = true)
26+
final public function autoconfigure(bool $autoconfigured = true): self
2727
{
2828
if ($autoconfigured && $this->definition instanceof ChildDefinition) {
2929
throw new InvalidArgumentException(sprintf('The service "%s" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.', $this->id));

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/AutowireTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait AutowireTrait
1818
*
1919
* @return $this
2020
*/
21-
final public function autowire(bool $autowired = true)
21+
final public function autowire(bool $autowired = true): self
2222
{
2323
$this->definition->setAutowired($autowired);
2424

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait BindTrait
3131
*
3232
* @return $this
3333
*/
34-
final public function bind($nameOrFqcn, $valueOrRef)
34+
final public function bind(string $nameOrFqcn, $valueOrRef): self
3535
{
3636
$valueOrRef = static::processValue($valueOrRef, true);
3737
if (!preg_match('/^(?:(?:array|bool|float|int|string)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/CallTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait CallTrait
2525
*
2626
* @throws InvalidArgumentException on empty $method param
2727
*/
28-
final public function call($method, array $arguments = [])
28+
final public function call(string $method, array $arguments = []): self
2929
{
3030
$this->definition->addMethodCall($method, static::processValue($arguments, true));
3131

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/ClassTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait ClassTrait
1818
*
1919
* @return $this
2020
*/
21-
final public function class($class)
21+
final public function class(?string $class): self
2222
{
2323
$this->definition->setClass($class);
2424

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/ConfiguratorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait ConfiguratorTrait
2020
*
2121
* @return $this
2222
*/
23-
final public function configurator($configurator)
23+
final public function configurator($configurator): self
2424
{
2525
$this->definition->setConfigurator(static::processValue($configurator, true));
2626

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/DecorateTrait.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ trait DecorateTrait
1818
/**
1919
* Sets the service that this service is decorating.
2020
*
21-
* @param string|null $id The decorated service id, use null to remove decoration
22-
* @param string|null $renamedId The new decorated service id
23-
* @param int $priority The priority of decoration
21+
* @param string|null $id The decorated service id, use null to remove decoration
2422
*
2523
* @return $this
2624
*
2725
* @throws InvalidArgumentException in case the decorated service id and the new decorated service id are equals
2826
*/
29-
final public function decorate($id, $renamedId = null, $priority = 0)
27+
final public function decorate(?string $id, string $renamedId = null, int $priority = 0): self
3028
{
3129
$this->definition->setDecoratedService($id, $renamedId, $priority);
3230

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/DeprecateTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait DeprecateTrait
2424
*
2525
* @throws InvalidArgumentException when the message template is invalid
2626
*/
27-
final public function deprecate($template = null)
27+
final public function deprecate(string $template = null): self
2828
{
2929
$this->definition->setDeprecated(true, $template);
3030

0 commit comments

Comments
 (0)