Skip to content

Commit 09f358d

Browse files
authored
Support Symfony 5.4 (#204)
1 parent 7cd67cf commit 09f358d

32 files changed

+164
-140
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: 'Setup PHP'
4242
uses: shivammathur/setup-php@v2
4343
with:
44-
php-version: 8.0
44+
php-version: 8.1
4545
ini-values: memory_limit=-1
4646
coverage: none
4747
tools: composer:v2
@@ -66,7 +66,7 @@ jobs:
6666
- name: 'Setup PHP'
6767
uses: shivammathur/setup-php@v2
6868
with:
69-
php-version: 8.0
69+
php-version: 8.1
7070
ini-values: memory_limit=-1
7171
coverage: none
7272
tools: composer:v2
@@ -86,14 +86,11 @@ jobs:
8686
fail-fast: false
8787
matrix:
8888
php-version:
89-
- '7.3'
9089
- '7.4'
9190
- '8.0'
91+
- '8.1'
9292
symfony-version:
93-
- '5.0'
94-
- '5.1'
95-
- '5.2'
96-
- '5.3'
93+
- '5.4'
9794
steps:
9895
- name: 'Checkout Code'
9996
uses: actions/checkout@v2
@@ -128,7 +125,7 @@ jobs:
128125
- name: 'Setup PHP'
129126
uses: shivammathur/setup-php@v2
130127
with:
131-
php-version: 7.4
128+
php-version: 8.1
132129
ini-values: memory_limit=-1
133130
coverage: pcov
134131
tools: composer:v2

Command/EnumDropCommentCommand.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,19 @@ final class EnumDropCommentCommand extends Command
3939
/** @var string */
4040
protected static $defaultDescription = 'Drop comment in DB for the column of registered ENUM type';
4141

42-
/** @var ManagerRegistry */
43-
private $registry;
44-
45-
/** @var EntityManagerInterface */
46-
private $em;
42+
private ManagerRegistry $registry;
43+
private EntityManagerInterface $em;
4744

4845
/** @var string[] */
49-
private $registeredEnumTypes = [];
46+
private array $registeredEnumTypes = [];
5047

5148
/** @var string|mixed */
5249
private $enumType;
5350

5451
/**
55-
* @param ManagerRegistry $registry
56-
* @param mixed[] $registeredTypes
57-
* @param string|null $name
52+
* @param ManagerRegistry $registry
53+
* @param array<string, array<string, string>> $registeredTypes
54+
* @param string|null $name
5855
*
5956
* @throws EnumTypeIsRegisteredButClassDoesNotExistException
6057
*/
@@ -193,10 +190,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
193190
}
194191
} catch (\Throwable $e) {
195192
$io->error($e->getMessage());
193+
$code = $e->getCode();
196194

197-
return $e->getCode();
195+
return \is_int($code) ? $code : self::FAILURE;
198196
}
199197

200-
return 0;
198+
return self::SUCCESS;
201199
}
202200
}

DBAL/Types/AbstractEnumType.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace Fresh\DoctrineEnumBundle\DBAL\Types;
1414

1515
use Doctrine\DBAL\Platforms\AbstractPlatform;
16-
use Doctrine\DBAL\Platforms\MySqlPlatform;
16+
use Doctrine\DBAL\Platforms\MySQLPlatform;
1717
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
1818
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
1919
use Doctrine\DBAL\Platforms\SqlitePlatform;
@@ -35,40 +35,37 @@
3535
*/
3636
abstract class AbstractEnumType extends Type
3737
{
38-
/** @var string */
39-
protected $name = '';
38+
protected string $name = '';
4039

4140
/**
4241
* @var array<TValue, TReadable> Array of ENUM Values, where ENUM values are keys and their readable versions are values
4342
*
4443
* @static
4544
*/
46-
protected static $choices = [];
45+
protected static array $choices = [];
4746

4847
/**
49-
* {@inheritdoc}
48+
* @param TValue $value
49+
* @param AbstractPlatform $platform
5050
*
5151
* @throws InvalidArgumentException
5252
*
53-
* @return TValue|null
53+
* @return TValue|int|string
5454
*/
5555
public function convertToDatabaseValue($value, AbstractPlatform $platform)
5656
{
57-
if (null === $value) {
58-
return null;
59-
}
60-
61-
if (!isset(static::$choices[$value])) {
57+
if (null !== $value && !isset(static::$choices[$value])) {
6258
throw new InvalidArgumentException(\sprintf('Invalid value "%s" for ENUM "%s".', $value, $this->getName()));
6359
}
6460

6561
return $value;
6662
}
6763

6864
/**
69-
* {@inheritdoc}
65+
* @param TValue $value
66+
* @param AbstractPlatform $platform
7067
*
71-
* @return TValue|null
68+
* @return TValue
7269
*/
7370
public function convertToPHPValue($value, AbstractPlatform $platform)
7471
{
@@ -89,8 +86,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
8986
/**
9087
* Gets the SQL declaration snippet for a field of this type.
9188
*
92-
* @param mixed[] $fieldDeclaration The field declaration
93-
* @param AbstractPlatform $platform The currently used database platform
89+
* @param array<string, string> $fieldDeclaration The field declaration
90+
* @param AbstractPlatform $platform The currently used database platform
9491
*
9592
* @return string
9693
*/
@@ -99,7 +96,8 @@ public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $pla
9996
$values = \implode(
10097
', ',
10198
\array_map(
102-
static function (string $value) {
99+
/** @var TValue $value */
100+
static function ($value) {
103101
return "'{$value}'";
104102
},
105103
static::getValues()
@@ -174,14 +172,20 @@ public static function getValues(): array
174172
*
175173
* @static
176174
*
175+
* @throws InvalidArgumentException
176+
*
177177
* @return TValue
178178
*/
179179
public static function getRandomValue()
180180
{
181181
$values = self::getValues();
182-
$randomKey = \random_int(0, \count($values) - 1);
183182

184-
return $values[$randomKey];
183+
$count = \count($values);
184+
if (0 === $count) {
185+
throw new InvalidArgumentException('There is no value in Enum type');
186+
}
187+
188+
return $values[\random_int(0, $count - 1)];
185189
}
186190

187191
/**
@@ -261,7 +265,7 @@ public static function getDefaultValue()
261265
*/
262266
public function getMappedDatabaseTypes(AbstractPlatform $platform): array
263267
{
264-
if ($platform instanceof MySqlPlatform) {
268+
if ($platform instanceof MySQLPlatform) {
265269
return \array_merge(parent::getMappedDatabaseTypes($platform), ['enum']);
266270
}
267271

DBAL/Types/DayOfWeekFullNameType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class DayOfWeekFullNameType extends AbstractEnumType
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
protected static $choices = [
41+
protected static array $choices = [
4242
self::MONDAY => 'Monday',
4343
self::TUESDAY => 'Tuesday',
4444
self::WEDNESDAY => 'Wednesday',

DBAL/Types/DayOfWeekShortNameType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class DayOfWeekShortNameType extends AbstractEnumType
3838
/**
3939
* {@inheritdoc}
4040
*/
41-
protected static $choices = [
41+
protected static array $choices = [
4242
self::MONDAY => 'Monday',
4343
self::TUESDAY => 'Tuesday',
4444
self::WEDNESDAY => 'Wednesday',

DBAL/Types/MonthFullNameType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class MonthFullNameType extends AbstractEnumType
4848
/**
4949
* {@inheritdoc}
5050
*/
51-
protected static $choices = [
51+
protected static array $choices = [
5252
self::JANUARY => 'January',
5353
self::FEBRUARY => 'February',
5454
self::MARCH => 'March',

DBAL/Types/MonthShortNameType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class MonthShortNameType extends AbstractEnumType
4848
/**
4949
* {@inheritdoc}
5050
*/
51-
protected static $choices = [
51+
protected static array $choices = [
5252
self::JANUARY => 'January',
5353
self::FEBRUARY => 'February',
5454
self::MARCH => 'March',

DependencyInjection/Compiler/RegisterEnumTypePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function process(ContainerBuilder $container): void
3838
/* @see \Doctrine\Bundle\DoctrineBundle\ConnectionFactory::createConnection */
3939
foreach ($doctrine->getConnectionNames() as $connectionName) {
4040
$definition = $container->getDefinition($connectionName);
41-
$mappingTypes = $definition->getArgument(3);
41+
$mappingTypes = (array) $definition->getArgument(3);
4242
if (!isset($mappingTypes['enum']) || 'string' !== $mappingTypes['enum']) {
4343
$mappingTypes['enum'] = 'string';
4444
$definition->setArgument(3, $mappingTypes);

Form/EnumTypeGuesser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
class EnumTypeGuesser extends DoctrineOrmTypeGuesser
3030
{
3131
/** @var string[] */
32-
private $registeredEnumTypes = [];
32+
private array $registeredEnumTypes = [];
3333

3434
/**
35-
* @param ManagerRegistry $registry
36-
* @param mixed[] $registeredTypes
35+
* @param ManagerRegistry $registry
36+
* @param array<string, array<string, string>> $registeredTypes
3737
*/
3838
public function __construct(ManagerRegistry $registry, array $registeredTypes)
3939
{

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313

1414
## Supported platforms 🧐
1515

16-
| MySQL | SQLite | PostgreSQL | MSSQL |
17-
|-------|--------|------------|-------|
16+
| PostgreSQL | SQLite | MySQL | MSSQL |
17+
|------------|--------|-------|-------|
1818

1919
## Installation 🌱
2020

21-
```composer req fresh/doctrine-enum-bundle='~7.3'```
21+
```composer req fresh/doctrine-enum-bundle='~7.4'```
2222

2323
##### Choose the version you need
2424

25-
| Bundle Version (X.Y.Z) | PHP | Symfony | Doctrine Bundle | Comment |
26-
|:----------------------:|:----------------:|:----------------:|:------------------:|:--------------------------|
27-
| `7.3.*` | `>= 7.3.0` | `>= 5.0` | `>= 2.1` | **Current version** |
28-
| `6.6.*` | `>= 7.1.3` | `4.3, 4.4` | `>= 2.0` | Previous version |
25+
| Bundle Version (X.Y.Z) | PHP | Symfony | Doctrine Bundle | Comment |
26+
|:----------------------:|:----------------:|:----------------:|:---------------:|:--------------------|
27+
| `7.4.*` | `>= 7.4.0` | `5.4` | `>= 2.5` | **Current version** |
28+
| `7.3.*` | `>= 7.3.0` | `5.0..5.3` | `>= 2.1` | Previous version |
2929

3030
#### Check the `config/bundles.php` file
3131

Resources/docs/example_of_using.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Player
6464
* @ORM\Column(name="id", type="integer")
6565
* @ORM\GeneratedValue(strategy="AUTO")
6666
*/
67-
protected $id;
67+
private $id;
6868
6969
/**
7070
* Note, that type of a field should be same as you set in Doctrine config
@@ -73,7 +73,7 @@ class Player
7373
* @ORM\Column(name="position", type="BasketballPositionType", nullable=false)
7474
* @DoctrineAssert\Enum(entity="App\DBAL\Types\BasketballPositionType")
7575
*/
76-
protected $position;
76+
private $position;
7777
7878
public function getId()
7979
{
@@ -82,6 +82,8 @@ class Player
8282
8383
public function setPosition(string $position)
8484
{
85+
BasketballPositionType::assertValidChoice($position);
86+
8587
$this->position = $position;
8688
}
8789

Tests/Command/EnumDropCommentCommandTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,10 @@ final class EnumDropCommentCommandTest extends TestCase
4242
/** @var AbstractPlatform|MockObject */
4343
private $platform;
4444

45-
/** @var Command */
46-
private $command;
47-
48-
/** @var ClassMetadataFactory */
49-
private $metadataFactory;
50-
51-
/** @var Application */
52-
private $application;
53-
54-
/** @var CommandTester */
55-
private $commandTester;
45+
private Command $command;
46+
private ClassMetadataFactory $metadataFactory;
47+
private Application $application;
48+
private CommandTester$commandTester;
5649

5750
protected function setUp(): void
5851
{

0 commit comments

Comments
 (0)