Skip to content

Commit ba5e3f6

Browse files
committed
chore(php8): rector form-bundle
Applied rules: * ClassPropertyAssignToConstructorPromotionRector (https://wiki.php.net/rfc/constructor_promotion php/php-src#5291) * ReadOnlyPropertyRector (https://wiki.php.net/rfc/readonly_properties_v2)
1 parent 8daad27 commit ba5e3f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+127
-338
lines changed

EMS/form-bundle/src/Components/Constraint/AbstractConstraintValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected function canCreateClass(string $class, string $value): bool
1212
new $class($value);
1313

1414
return true;
15-
} catch (\Exception $exception) {
15+
} catch (\Exception) {
1616
return false;
1717
}
1818
}

EMS/form-bundle/src/Components/Constraint/IsBirthDateValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private function getDate(string $dateString): \DateTimeImmutable
4141
{
4242
try {
4343
return new \DateTimeImmutable($dateString);
44-
} catch (\Exception $exception) {
44+
} catch (\Exception) {
4545
throw new RuntimeException(\sprintf('Could not create date from string "%s"', $dateString));
4646
}
4747
}

EMS/form-bundle/src/Components/Constraint/IsExpressionValidator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010

1111
class IsExpressionValidator extends ConstraintValidator
1212
{
13-
private ExpressionServiceInterface $expressionService;
14-
15-
public function __construct(ExpressionServiceInterface $expressionService)
13+
public function __construct(private readonly ExpressionServiceInterface $expressionService)
1614
{
17-
$this->expressionService = $expressionService;
1815
}
1916

2017
public function validate($value, Constraint $constraint): void

EMS/form-bundle/src/Components/Constraint/IsRequiredIfValidator.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010

1111
class IsRequiredIfValidator extends ConstraintValidator
1212
{
13-
private LoggerInterface $logger;
14-
15-
public function __construct(LoggerInterface $logger)
13+
public function __construct(private readonly LoggerInterface $logger)
1614
{
17-
$this->logger = $logger;
1815
}
1916

2017
public function validate($value, Constraint $constraint): void
@@ -53,8 +50,7 @@ private function isRequiredIf(?string $expression): bool
5350
}
5451
}
5552

56-
/** @param mixed $value */
57-
private function isEmpty($value): bool
53+
private function isEmpty(mixed $value): bool
5854
{
5955
if (null === $value || '' === $value) {
6056
return true;

EMS/form-bundle/src/Components/Constraint/IsRequiredWithoutValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function validate($value, Constraint $constraint): void
2020
}
2121

2222
if (\is_null($constraint->otherField)) {
23-
throw new \InvalidArgumentException(\sprintf('The %s::$otherField parameter value is not valid.', \get_class($constraint)));
23+
throw new \InvalidArgumentException(\sprintf('The %s::$otherField parameter value is not valid.', $constraint::class));
2424
}
2525

2626
if (!$this->isRequiredWithout($value, $constraint->otherField)) {
@@ -34,7 +34,7 @@ private function isRequiredWithout(?string $value, string $otherField): bool
3434
{
3535
try {
3636
$otherFieldValue = $this->context->getRoot()->get($otherField)->getData();
37-
} catch (\Exception $exception) {
37+
} catch (\Exception) {
3838
return false;
3939
}
4040

EMS/form-bundle/src/Components/Constraint/IsVerificationCodeValidator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111

1212
class IsVerificationCodeValidator extends ConstraintValidator
1313
{
14-
private ConfirmationService $confirmationService;
15-
16-
public function __construct(ConfirmationService $confirmationService)
14+
public function __construct(private readonly ConfirmationService $confirmationService)
1715
{
18-
$this->confirmationService = $confirmationService;
1916
}
2017

2118
public function validate($value, Constraint $constraint): void

EMS/form-bundle/src/Components/DataTransformers/ForgivingNumberDataTransformer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
*/
1111
class ForgivingNumberDataTransformer implements DataTransformerInterface
1212
{
13-
/** @var string[] */
14-
private array $transformerClasses;
15-
1613
/**
1714
* @param string[] $transformerClasses
1815
*/
19-
public function __construct(array $transformerClasses)
16+
public function __construct(private readonly array $transformerClasses)
2017
{
21-
$this->transformerClasses = $transformerClasses;
2218
}
2319

2420
public function transform($value)
@@ -39,7 +35,7 @@ public function reverseTransform($value)
3935
if (\method_exists($validation, 'transform')) {
4036
return $validation->transform();
4137
}
42-
} catch (\Exception $exception) {
38+
} catch (\Exception) {
4339
continue;
4440
}
4541
}

EMS/form-bundle/src/Components/EventSubscriber/NestedChoiceEventSubscriber.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@
1212

1313
class NestedChoiceEventSubscriber implements EventSubscriberInterface
1414
{
15-
private FieldInterface $field;
16-
private FieldChoicesConfig $choices;
17-
18-
public function __construct(FieldInterface $field, FieldChoicesConfig $choices)
15+
public function __construct(private readonly FieldInterface $field, private readonly FieldChoicesConfig $choices)
1916
{
20-
$this->field = $field;
21-
$this->choices = $choices;
2217
}
2318

2419
/** @return string[] */
@@ -100,7 +95,7 @@ private function addField(string $fieldName, string $choice, FormInterface $form
10095

10196
try {
10297
$this->choices->addChoice($choice);
103-
} catch (\Exception $exception) {
98+
} catch (\Exception) {
10499
return;
105100
}
106101

EMS/form-bundle/src/Components/Field/AbstractField.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010

1111
abstract class AbstractField implements FieldInterface
1212
{
13-
/** @var FieldConfig */
14-
protected $config;
1513
/** @var ValidationInterface[] */
1614
private array $validations = [];
1715

18-
public function __construct(FieldConfig $config)
16+
public function __construct(protected FieldConfig $config)
1917
{
20-
$this->config = $config;
21-
2218
foreach ($config->getValidations() as $id => $validationConfig) {
2319
$this->validations[$id] = $this->createValidation($validationConfig);
2420
}
@@ -111,7 +107,7 @@ private function getValidationHtml5Attribute(): array
111107
$html5Attributes = [];
112108

113109
foreach ($this->validations as $validation) {
114-
$html5Attributes = \array_merge($html5Attributes, $validation->getHtml5Attribute());
110+
$html5Attributes = [...$html5Attributes, ...$validation->getHtml5Attribute()];
115111
}
116112

117113
return $html5Attributes;

EMS/form-bundle/src/Components/Form.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121

2222
class Form extends AbstractType
2323
{
24-
private FormConfigFactory $configFactory;
25-
26-
public function __construct(FormConfigFactory $configFactory)
24+
public function __construct(private readonly FormConfigFactory $configFactory)
2725
{
28-
$this->configFactory = $configFactory;
2926
}
3027

3128
/**

0 commit comments

Comments
 (0)