Skip to content

Commit 0528648

Browse files
authored
Remove PHP/Symfony versions matrix hacks (#62)
1 parent cafca27 commit 0528648

25 files changed

+172
-358
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ class Member
8989
}
9090
```
9191

92-
> **note** both PHP Attributes & Annotations are supported :
93-
> ```php
94-
> /**
95-
> * @Enum(StatusEnum::class)
96-
> */
97-
> public ?string $status = null;
98-
> ```
99-
10092
### Setting up the form
10193

10294
Now that validation is configured, the only thing we have to do is to add a field on our form :

src/Enum.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
*/
1313
class Enum implements EnumInterface
1414
{
15-
/**
16-
* @var string
17-
*/
18-
private $name;
15+
private string $name;
1916

2017
/**
2118
* @var array<string, mixed>|null
2219
*/
23-
private $choices;
20+
private array|null $choices;
2421

2522
/**
2623
* @param array<string, mixed>|null $choices Allowed to be null if you are extending this class
@@ -41,8 +38,10 @@ public function __construct(?array $choices, ?string $name = null)
4138
if ($name === null) {
4239
$name = static::class;
4340
if (
44-
\strpos($name, 'Yokai\\EnumBundle\\') === 0 // using FQCN as name is only allowed for other namespaces
45-
&& \strpos($name, 'Yokai\\EnumBundle\\Tests\\') !== 0 // except for our tests
41+
// using FQCN as name is only allowed for other namespaces
42+
\str_starts_with($name, 'Yokai\\EnumBundle\\')
43+
// except for our tests
44+
&& !\str_starts_with($name, 'Yokai\\EnumBundle\\Tests\\')
4645
) {
4746
throw new LogicException(
4847
'When using ' . static::class . ', $name argument in ' . __METHOD__ . ' method cannot be null'
@@ -67,7 +66,7 @@ public function getValues(): array
6766
return \array_values($this->choices);
6867
}
6968

70-
public function getLabel($value): string
69+
public function getLabel(mixed $value): string
7170
{
7271
$this->init();
7372

src/EnumInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ public function getValues(): array;
2525

2626
/**
2727
* Returns enum value label.
28-
*
29-
* @param mixed $value
3028
*/
31-
public function getLabel($value): string;
29+
public function getLabel(mixed $value): string;
3230

3331
/**
3432
* Returns enum identifier (must be unique across app).

src/EnumRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class EnumRegistry
1515
/**
1616
* @var EnumInterface[]
1717
*/
18-
private $enums = [];
18+
private array $enums = [];
1919

2020
/**
2121
* @throws LogicException

src/Form/Type/EnumType.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
*/
1717
final class EnumType extends AbstractType
1818
{
19-
/**
20-
* @var EnumRegistry
21-
*/
22-
private $enumRegistry;
19+
private EnumRegistry $enumRegistry;
2320

2421
public function __construct(EnumRegistry $enumRegistry)
2522
{

src/TranslatedEnum.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,13 @@ class TranslatedEnum extends Enum
1515
/**
1616
* @var array<int|string, mixed>
1717
*/
18-
private $values;
18+
private array $values;
1919

20-
/**
21-
* @var TranslatorInterface
22-
*/
23-
private $translator;
20+
private TranslatorInterface $translator;
2421

25-
/**
26-
* @var string
27-
*/
28-
private $transPattern;
22+
private string $transPattern;
2923

30-
/**
31-
* @var string
32-
*/
33-
private $transDomain;
24+
private string $transDomain;
3425

3526
/**
3627
* @param array<int|string, mixed> $values
@@ -44,7 +35,7 @@ public function __construct(
4435
string $transDomain = 'messages',
4536
?string $name = null
4637
) {
47-
if (\strpos($transPattern, '%s') === false) {
38+
if (!\str_contains($transPattern, '%s')) {
4839
throw LogicException::placeholderRequired($transPattern);
4940
}
5041

src/Twig/Extension/EnumExtension.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
*/
1515
final class EnumExtension extends AbstractExtension
1616
{
17-
/**
18-
* @var EnumRegistry
19-
*/
20-
private $registry;
17+
private EnumRegistry $registry;
2118

2219
public function __construct(EnumRegistry $registry)
2320
{

src/Validator/Constraints/Enum.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
use Symfony\Component\Validator\Constraints\Choice;
88

99
/**
10-
* @Annotation
11-
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
12-
*
1310
* @author Yann Eugoné <[email protected]>
1411
*/
1512
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)]
1613
final class Enum extends Choice
1714
{
18-
/**
19-
* @var string
20-
*/
21-
public $enum;
15+
public string $enum;
2216

2317
/**
2418
* @param array<string, mixed> $options

src/Validator/Constraints/EnumValidator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
final class EnumValidator extends ChoiceValidator
1717
{
18-
/**
19-
* @var EnumRegistry
20-
*/
21-
private $enumRegistry;
18+
private EnumRegistry $enumRegistry;
2219

2320
public function __construct(EnumRegistry $enumRegistry)
2421
{
@@ -34,7 +31,7 @@ public function validate(mixed $value, Constraint $constraint): void
3431
$constraint->choices = null;
3532
$constraint->callback = null;
3633

37-
if (!$constraint->enum) {
34+
if (!isset($constraint->enum)) {
3835
throw new ConstraintDefinitionException('"enum" must be specified on constraint Enum');
3936
}
4037

tests/Integration/config/packages/annotations.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)