Skip to content

Commit 00d26dc

Browse files
Convert properties to constructor promotion
1 parent fa9e06d commit 00d26dc

17 files changed

+28
-152
lines changed

src/Database/SoftDeletableSubscriber.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@ class SoftDeletableSubscriber implements EventSubscriber
1515
*/
1616
const FIELD_NAME = 'deletedBy';
1717

18-
/**
19-
* @var TokenStorageInterface
20-
*/
21-
private $tokenStorage;
22-
2318
/**
2419
* SoftDeletableSubscriber constructor.
2520
*
2621
* @param TokenStorageInterface $tokenStorage
2722
*/
28-
public function __construct(TokenStorageInterface $tokenStorage)
23+
public function __construct(private TokenStorageInterface $tokenStorage)
2924
{
30-
$this->tokenStorage = $tokenStorage;
3125
}
3226

3327
/**

src/Database/SoftDeletableSymfonyCacheWarmer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88

99
class SoftDeletableSymfonyCacheWarmer implements CacheWarmerInterface
1010
{
11-
/**
12-
* @var bool
13-
*/
14-
private $useUtc;
15-
16-
public function __construct(bool $useUtc)
11+
public function __construct(private bool $useUtc)
1712
{
18-
$this->useUtc = $useUtc;
1913
}
2014

2115
public static function registerGedmoType(): void

src/Database/SoftDeletableSymfonySubscriber.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616
class SoftDeletableSymfonySubscriber implements EventSubscriberInterface
1717
{
1818

19-
/**
20-
* @var bool
21-
*/
22-
private $useUtc;
23-
24-
public function __construct(bool $useUtc)
19+
public function __construct(private bool $useUtc)
2520
{
26-
$this->useUtc = $useUtc;
2721
}
2822

2923
public static function getSubscribedEvents()

src/Email/EmailService.php

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,6 @@
1717
*/
1818
class EmailService
1919
{
20-
/**
21-
* @var MailerInterface
22-
*/
23-
private $mailer;
24-
/**
25-
* @var string
26-
*/
27-
private $senderEmail;
28-
/**
29-
* @var string|null
30-
*/
31-
private $senderName;
32-
/**
33-
* @var TranslatorInterface|null
34-
*/
35-
private $translator;
36-
/**
37-
* @var TransportInterface
38-
*/
39-
private $transport;
40-
4120
/**
4221
* EmailService constructor.
4322
*
@@ -48,17 +27,12 @@ class EmailService
4827
* @param TransportInterface $transport
4928
*/
5029
public function __construct(
51-
MailerInterface $mailer,
52-
string $senderEmail,
53-
?string $senderName,
54-
?TranslatorInterface $translator,
55-
TransportInterface $transport)
30+
private MailerInterface $mailer,
31+
private string $senderEmail,
32+
private ?string $senderName,
33+
private ?TranslatorInterface $translator,
34+
private TransportInterface $transport)
5635
{
57-
$this->mailer = $mailer;
58-
$this->senderEmail = $senderEmail;
59-
$this->senderName = $senderName;
60-
$this->translator = $translator;
61-
$this->transport = $transport;
6236
}
6337

6438
/**

src/Exception/EntityValidationFailedException.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@
88

99
class EntityValidationFailedException extends Exception
1010
{
11-
/**
12-
* @var ConstraintViolationListInterface|null
13-
*/
14-
private $violationList;
15-
16-
public function __construct(?ConstraintViolationListInterface $violationList = NULL, ?string $message = NULL)
11+
public function __construct(private ?ConstraintViolationListInterface $violationList = NULL, ?string $message = NULL)
1712
{
18-
$this->violationList = $violationList;
19-
2013
if ($violationList !== NULL) {
2114
$messages = [];
2215
foreach ($violationList as $violation) {

src/Exception/Handler/EntityValidationFailedExceptionHandler.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,11 @@
1313

1414
class EntityValidationFailedExceptionHandler implements EventSubscriberInterface
1515
{
16-
/**
17-
* @var string
18-
*/
19-
private $controllerPrefix;
20-
/**
21-
* @var string
22-
*/
23-
private $dataField;
24-
25-
/**
26-
* @var SerializerInterface
27-
*/
28-
private $serializer;
29-
30-
public function __construct(SerializerInterface $serializer, string $controllerPrefix, string $dataField)
16+
public function __construct(
17+
private SerializerInterface $serializer,
18+
private string $controllerPrefix,
19+
private string $dataField)
3120
{
32-
$this->serializer = $serializer;
33-
$this->controllerPrefix = $controllerPrefix;
34-
$this->dataField = $dataField;
3521
}
3622

3723
public static function getSubscribedEvents()

src/Form/Extension/Select2Extension.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@
2121
*/
2222
class Select2Extension extends AbstractTypeExtension
2323
{
24-
/**
25-
* @var TranslatorInterface|null
26-
*/
27-
private $translator;
28-
29-
public function __construct(?TranslatorInterface $translator)
24+
public function __construct(private ?TranslatorInterface $translator)
3025
{
31-
$this->translator = $translator;
3226
}
3327

3428
public function buildForm(FormBuilderInterface $builder, array $options)

src/Form/Type/Select2EntitySearchType.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,8 @@
2121
*/
2222
class Select2EntitySearchType extends AbstractType
2323
{
24-
/**
25-
* @var PropertyAccessorInterface
26-
*/
27-
private $propertyAccessor;
28-
/**
29-
* @var ManagerRegistry
30-
*/
31-
private $registry;
32-
33-
public function __construct(ManagerRegistry $registry, PropertyAccessorInterface $propertyAccessor)
24+
public function __construct(private ManagerRegistry $registry, private PropertyAccessorInterface $propertyAccessor)
3425
{
35-
$this->registry = $registry;
36-
$this->propertyAccessor = $propertyAccessor;
3726
}
3827

3928
public function buildForm(FormBuilderInterface $builder, array $options)

src/Helper/DateTimeProvider.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
*/
1111
class DateTimeProvider
1212
{
13-
private $now;
14-
15-
public function __construct(string $now = 'now')
13+
public function __construct(private string $now = 'now')
1614
{
17-
$this->now = $now;
1815
}
1916

2017
/**

src/Helper/GravatarHelper.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@
99
*/
1010
class GravatarHelper
1111
{
12-
/**
13-
* The fallback style of gravatar to use in case there is not gravatar available
14-
*
15-
* @var string
16-
*/
17-
private $fallbackStyle;
18-
19-
public function __construct(string $fallbackStyle)
12+
public function __construct(private string $fallbackStyle)
2013
{
21-
$this->fallbackStyle = $fallbackStyle;
2214
}
2315

2416
/**

src/Helper/SpreadsheetHelper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020
class SpreadsheetHelper
2121
{
2222

23-
/** @var TranslatorInterface */
24-
private $translator;
25-
2623
/**
2724
* SpreadsheetHelper constructor.
2825
*
2926
* @param TranslatorInterface $translator
3027
*/
31-
public function __construct(TranslatorInterface $translator)
28+
public function __construct(private TranslatorInterface $translator)
3229
{
33-
$this->translator = $translator;
3430
}
3531

3632
/**

src/Helper/UtcHelper.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111
class UtcHelper
1212
{
1313

14-
/**
15-
* @var DateTimeZone
16-
*/
17-
private static $utc;
14+
private static \DateTimeZone $utc;
1815

19-
/**
20-
* @var DateTimeZone
21-
*/
22-
private static $local;
16+
private static \DateTimeZone $local;
2317

2418
/**
2519
* @return DateTimeZone

src/Ical/IcalProvider.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
class IcalProvider
1616
{
1717

18-
/** @var IcsProvider */
19-
protected $provider;
20-
2118
/**
2219
* IcalProvider constructor.
2320
*/
24-
public function __construct(IcsProvider $provider)
21+
public function __construct(protected IcsProvider $provider)
2522
{
26-
$this->provider = $provider;
2723
}
2824

2925
/**

src/IdMap/IdMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class IdMap implements Countable, IteratorAggregate
1717
{
1818
/** @var array<int, T> */
19-
private $elements;
19+
private array $elements;
2020

2121
/** @param T[] $objects */
2222
public function __construct(array $objects = [])

src/Serializer/StaticSerializer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
class StaticSerializer implements EventSubscriberInterface
1515
{
1616

17-
/** @var SerializerInterface|null */
18-
private static $serializer = NULL;
19-
/** @var SerializationContextFactoryInterface|null */
20-
private static $serializationContextFactory = NULL;
17+
private static ?SerializerInterface $serializer = NULL;
18+
private static ?SerializationContextFactoryInterface $serializationContextFactory = NULL;
2119

2220
/**
2321
* EntitySnapshotter constructor.

src/Twig/GravatarExtension.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
*/
1414
class GravatarExtension extends AbstractExtension
1515
{
16-
/**
17-
* @var GravatarHelper
18-
*/
19-
private $gravatarHelper;
20-
21-
public function __construct(GravatarHelper $gravatarHelper)
16+
public function __construct(private GravatarHelper $gravatarHelper)
2217
{
23-
$this->gravatarHelper = $gravatarHelper;
2418
}
2519

2620
/**

src/Twig/JmsSerializerExtension.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,10 @@
99

1010
class JmsSerializerExtension extends AbstractExtension
1111
{
12-
/**
13-
* @var SerializationContextFactoryInterface
14-
*/
15-
private $contextFactory;
16-
/**
17-
* @var SerializerInterface
18-
*/
19-
private $serializer;
20-
21-
public function __construct(SerializerInterface $serializer, SerializationContextFactoryInterface $contextFactory)
12+
public function __construct(
13+
private SerializerInterface $serializer,
14+
private SerializationContextFactoryInterface $contextFactory)
2215
{
23-
$this->serializer = $serializer;
24-
$this->contextFactory = $contextFactory;
2516
}
2617

2718
public function getFilters()

0 commit comments

Comments
 (0)