Skip to content

Commit 4b6c9dc

Browse files
authored
Merge pull request #147 from fre5h/feature-update
Refactoring
2 parents 3c50dda + 65d4770 commit 4b6c9dc

15 files changed

+57
-53
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ php:
88
- 7.3
99

1010
env:
11-
- SYMFONY_VERSION=4.0.*
12-
- SYMFONY_VERSION=4.1.*
13-
- SYMFONY_VERSION=4.2.*
1411
- SYMFONY_VERSION=4.3.*
1512

1613
before_install:

Form/EnumTypeGuesser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Form;
1414

15+
use Doctrine\Common\Persistence\ManagerRegistry;
1516
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
1617
use Fresh\DoctrineEnumBundle\Exception\EnumType\EnumTypeIsRegisteredButClassDoesNotExistException;
1718
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
18-
use Symfony\Bridge\Doctrine\RegistryInterface;
1919
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
2020
use Symfony\Component\Form\Guess\Guess;
2121
use Symfony\Component\Form\Guess\TypeGuess;
@@ -32,10 +32,10 @@ class EnumTypeGuesser extends DoctrineOrmTypeGuesser
3232
protected $registeredEnumTypes = [];
3333

3434
/**
35-
* @param RegistryInterface $registry
36-
* @param array $registeredTypes
35+
* @param ManagerRegistry $registry
36+
* @param array $registeredTypes
3737
*/
38-
public function __construct(RegistryInterface $registry, array $registeredTypes)
38+
public function __construct(ManagerRegistry $registry, array $registeredTypes)
3939
{
4040
parent::__construct($registry);
4141

@@ -66,7 +66,7 @@ public function guessType($class, $property): ?TypeGuess
6666
$fieldType = $metadata->getTypeOfField($property);
6767

6868
// This is not one of the registered ENUM types
69-
if (!isset($this->registeredEnumTypes[$fieldType])) {
69+
if (!\is_string($fieldType) || !isset($this->registeredEnumTypes[$fieldType])) {
7070
return null;
7171
}
7272

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ Provides support of **ENUM type** for Doctrine in Symfony applications.
3232

3333
#### Check the `config/bundles.php` file
3434

35-
By default Symfony Flex will add FreshDoctrineEnumBundle to the `config/bundles.php` file. But in case when you ignored `contrib-recipe` during bundle installation it would not be added. In this case add the bundle manually.
35+
By default Symfony Flex will add this bundle to the `config/bundles.php` file.
36+
But in case when you ignored `contrib-recipe` during bundle installation it would not be added. In this case add the bundle manually.
3637

3738
```php
3839
# config/bundles.php
3940

4041
return [
41-
// other bundles
42+
// Other bundles...
4243
Fresh\DoctrineEnumBundle\FreshDoctrineEnumBundle::class => ['all' => true],
43-
// other bundles
44+
// Other bundles...
4445
];
4546
```
4647

Tests/DBAL/Types/AbstractEnumTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @author Artem Henvald <genvaldartem@gmail.com>
3131
* @author Ben Davies <ben.davies@gmail.com>
3232
*/
33-
class AbstractEnumTypeTest extends TestCase
33+
final class AbstractEnumTypeTest extends TestCase
3434
{
3535
/** @var AbstractEnumType */
3636
private $type;

Tests/DependencyInjection/FreshDoctrineEnumExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author Artem Henvald <genvaldartem@gmail.com>
2727
*/
28-
class FreshDoctrineEnumExtensionTest extends TestCase
28+
final class FreshDoctrineEnumExtensionTest extends TestCase
2929
{
3030
/** @var FreshDoctrineEnumExtension */
3131
private $extension;

Tests/Form/EnumTypeGuesserTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Tests\Form;
1414

15+
use Doctrine\Common\Persistence\ManagerRegistry;
1516
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1617
use Fresh\DoctrineEnumBundle\Exception\EnumType\EnumTypeIsRegisteredButClassDoesNotExistException;
1718
use Fresh\DoctrineEnumBundle\Form\EnumTypeGuesser;
@@ -20,7 +21,6 @@
2021
use Fresh\DoctrineEnumBundle\Tests\Fixtures\DBAL\Types\NotAChildType;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
23-
use Symfony\Bridge\Doctrine\RegistryInterface;
2424
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
2525
use Symfony\Component\Form\Guess\Guess;
2626
use Symfony\Component\Form\Guess\TypeGuess;
@@ -30,7 +30,7 @@
3030
*
3131
* @author Artem Henvald <genvaldartem@gmail.com>
3232
*/
33-
class EnumTypeGuesserTest extends TestCase
33+
final class EnumTypeGuesserTest extends TestCase
3434
{
3535
public function testNullResultWhenClassMetadataNotFound(): void
3636
{
@@ -85,12 +85,12 @@ public function testNullResultWhenEnumTypeNotRegistered(): void
8585

8686
public function testExceptionWhenClassDoesNotExist(): void
8787
{
88-
$registry = $this->createMock(RegistryInterface::class);
88+
$registry = $this->createMock(ManagerRegistry::class);
8989

9090
$registeredTypes = [
9191
'stub' => [
9292
'class' => '\Acme\Foo\Bar\Baz',
93-
]
93+
],
9494
];
9595

9696
/** @var EnumTypeGuesser|MockObject $enumTypeGuesser */
@@ -127,12 +127,12 @@ public function testExceptionWhenClassDoesNotExist(): void
127127

128128
public function testNullResultWhenIsNotChildOfAbstractEnumType(): void
129129
{
130-
$registry = $this->createMock(RegistryInterface::class);
130+
$registry = $this->createMock(ManagerRegistry::class);
131131

132132
$registeredTypes = [
133133
'NotAChildType' => [
134134
'class' => NotAChildType::class,
135-
]
135+
],
136136
];
137137

138138
/** @var EnumTypeGuesser|MockObject $enumTypeGuesser */
@@ -167,12 +167,12 @@ public function testNullResultWhenIsNotChildOfAbstractEnumType(): void
167167

168168
public function testSuccessfulTypeGuessingWithAncestor(): void
169169
{
170-
$registry = $this->createMock(RegistryInterface::class);
170+
$registry = $this->createMock(ManagerRegistry::class);
171171

172172
$registeredTypes = [
173173
'InheritedType' => [
174174
'class' => InheritedType::class,
175-
]
175+
],
176176
];
177177

178178
/** @var EnumTypeGuesser|MockObject $enumTypeGuesser */
@@ -222,12 +222,12 @@ public function testSuccessfulTypeGuessingWithAncestor(): void
222222

223223
public function testSuccessfulTypeGuessing(): void
224224
{
225-
$registry = $this->createMock(RegistryInterface::class);
225+
$registry = $this->createMock(ManagerRegistry::class);
226226

227227
$registeredTypes = [
228228
'BasketballPositionType' => [
229229
'class' => BasketballPositionType::class,
230-
]
230+
],
231231
];
232232

233233
/** @var EnumTypeGuesser|MockObject $enumTypeGuesser */

Tests/FreshDoctrineEnumBundleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author Artem Henvald <genvaldartem@gmail.com>
2727
*/
28-
class FreshDoctrineEnumBundleTest extends TestCase
28+
final class FreshDoctrineEnumBundleTest extends TestCase
2929
{
3030
/** @var ContainerInterface|MockObject */
3131
private $container;
@@ -175,8 +175,8 @@ public function testMissedDoctrine(): void
175175
->willReturn(null)
176176
;
177177

178-
self::expectException(\InvalidArgumentException::class);
179-
self::expectExceptionMessage('Service "doctrine" is missed in container');
178+
$this->expectException(\InvalidArgumentException::class);
179+
$this->expectExceptionMessage('Service "doctrine" is missed in container');
180180

181181
$bundle = new FreshDoctrineEnumBundle();
182182
$bundle->setContainer($this->container);

Tests/Twig/Extension/EnumConstantExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Artem Henvald <genvaldartem@gmail.com>
3030
*/
31-
class EnumConstantExtensionTest extends TestCase
31+
final class EnumConstantExtensionTest extends TestCase
3232
{
3333
/** @var EnumConstantTwigExtension */
3434
private $enumConstantExtension;

Tests/Twig/Extension/EnumValuesAsArrayExtensionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @author Artem Henvald <genvaldartem@gmail.com>
2626
*/
27-
class EnumValuesAsArrayExtensionTest extends TestCase
27+
final class EnumValuesAsArrayExtensionTest extends TestCase
2828
{
2929
/** @var EnumValuesAsArrayTwigExtension */
3030
private $enumValuesAsArrayTwigExtension;
@@ -95,8 +95,8 @@ public function testInvalidCallable(): void
9595
$property->setValue($extension, ['invalid_callable' => 'dummy']);
9696
$property->setAccessible(false);
9797

98-
self::expectException(\LogicException::class);
99-
self::expectExceptionMessage('dummy::getReadableValues is not a valid exception');
98+
$this->expectException(\LogicException::class);
99+
$this->expectExceptionMessage('dummy::getReadableValues is not a valid exception');
100100

101101
$extension->getReadableEnumValuesAsArray('invalid_callable');
102102
}

Tests/Twig/Extension/ReadableEnumValueExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Artem Henvald <genvaldartem@gmail.com>
2929
*/
30-
class ReadableEnumValueExtensionTest extends TestCase
30+
final class ReadableEnumValueExtensionTest extends TestCase
3131
{
3232
/** @var ReadableEnumValueTwigExtension */
3333
private $readableEnumValueExtension;

Tests/Validator/EnumTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author Artem Henvald <genvaldartem@gmail.com>
2424
*/
25-
class EnumTest extends TestCase
25+
final class EnumTest extends TestCase
2626
{
2727
public function testConstructor(): void
2828
{

Tests/Validator/EnumValidatorTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @author Artem Henvald <genvaldartem@gmail.com>
2828
*/
29-
class EnumValidatorTest extends TestCase
29+
final class EnumValidatorTest extends TestCase
3030
{
3131
/** @var EnumValidator */
3232
private $enumValidator;
@@ -87,12 +87,19 @@ public function testInvalidBasketballPositionType(): void
8787
$constraintValidationBuilder = $this->createMock(ConstraintViolationBuilder::class);
8888

8989
$constraintValidationBuilder
90-
->expects(self::once())
90+
->expects(self::at(0))
9191
->method('setParameter')
9292
->with($this->equalTo('{{ value }}'), $this->equalTo('"Pitcher"'))
9393
->willReturnSelf()
9494
;
9595

96+
$constraintValidationBuilder
97+
->expects(self::at(1))
98+
->method('setParameter')
99+
->with($this->equalTo('{{ choices }}'), $this->equalTo('"PG", "SG", "SF", "PF", "C"'))
100+
->willReturnSelf()
101+
;
102+
96103
$constraintValidationBuilder
97104
->expects(self::once())
98105
->method('setCode')

Twig/Extension/AbstractEnumTwigExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
abstract class AbstractEnumTwigExtension extends AbstractExtension
2626
{
27-
/** @var string[] */
27+
/** @var string[]|AbstractEnumType[] */
2828
protected $registeredEnumTypes = [];
2929

3030
/** @var array */
@@ -37,7 +37,7 @@ public function __construct(array $registeredTypes)
3737
{
3838
foreach ($registeredTypes as $type => $details) {
3939
$class = $details['class'];
40-
if (\is_subclass_of($class, AbstractEnumType::class) && \is_string($class)) {
40+
if (\is_string($class) && \is_subclass_of($class, AbstractEnumType::class)) {
4141
$this->registeredEnumTypes[$type] = $class;
4242
}
4343
}

Twig/Extension/EnumValuesAsArrayTwigExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private function callEnumTypeStaticMethod(string $enumType, string $staticMethod
8080
throw new \LogicException(\sprintf('%s::%s is not a valid exception', $this->registeredEnumTypes[$enumType], $staticMethodName));
8181
}
8282

83-
return \call_user_func($function);
83+
return $function();
8484
}
8585

8686
throw $this->createNoRegisteredEnumTypesException();

composer.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,24 @@
2323
},
2424
"require": {
2525
"php": ">=7.1.3",
26-
"doctrine/doctrine-bundle": "^1.6.10",
27-
"doctrine/common": "^2.8",
28-
"doctrine/orm": "~2.4",
29-
"symfony/config": "^4.0",
30-
"symfony/dependency-injection": "^4.0",
31-
"symfony/doctrine-bridge": "^4.0",
32-
"symfony/framework-bundle": "^4.0",
33-
"symfony/http-kernel": "^4.0",
34-
"symfony/validator": "^4.0",
35-
"twig/twig": "~2.4"
26+
"doctrine/doctrine-bundle": "~1.11",
27+
"doctrine/common": "~2.8",
28+
"doctrine/orm": "~2.6",
29+
"symfony/config": "^4.3",
30+
"symfony/dependency-injection": "^4.3",
31+
"symfony/doctrine-bridge": "^4.3",
32+
"symfony/framework-bundle": "^4.3",
33+
"symfony/http-kernel": "^4.3",
34+
"symfony/validator": "^4.3",
35+
"twig/twig": "~2.11"
3636
},
3737
"require-dev": {
38-
"phpstan/phpstan": "^0.10",
39-
"phpstan/phpstan-doctrine": "^0.10",
40-
"phpstan/phpstan-phpunit": "^0.10",
38+
"escapestudios/symfony2-coding-standard": "^3.8",
39+
"phpstan/phpstan": "^0.11",
40+
"phpstan/phpstan-doctrine":"^0.11",
41+
"phpstan/phpstan-phpunit": "^0.11",
4142
"phpunit/phpunit": "^7.5",
42-
"escapestudios/symfony2-coding-standard": "^3.4",
43-
"squizlabs/php_codesniffer": "^3.3",
44-
"symfony/form": "^4.0"
43+
"symfony/form": "^4.3"
4544
},
4645
"autoload": {
4746
"psr-4": {

0 commit comments

Comments
 (0)