diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index ca64fa59..26b78243 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -24,20 +24,21 @@ ->setFinder($finder) ->setRules([ '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'header_comment' => ['header' => $header], + 'native_function_invocation' => ['include' => ['@compiler_optimized']], + 'no_unneeded_final_method' => false, // final private __construct is a valid use-case + 'ordered_imports' => true, 'php_unit_namespaced' => true, 'php_unit_method_casing' => false, - 'psr_autoloading' => true, - 'concat_space' => ['spacing' => 'one'], - 'phpdoc_summary' => false, 'phpdoc_annotation_without_dot' => false, + 'phpdoc_summary' => false, 'phpdoc_order' => true, - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'psr_autoloading' => true, + 'single_line_throw' => false, 'simplified_null_return' => false, - 'header_comment' => ['header' => $header], 'yoda_style' => [], - 'no_unneeded_final_method' => false, // final private __construct is a valid use-case - 'native_function_invocation' => ['include' => ['@compiler_optimized']], - 'single_line_throw' => false, ]) ; diff --git a/Makefile b/Makefile index 5d731833..0ea81b0a 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ install: setup install: rm -f composer.lock composer config minimum-stability --unset - composer remove --no-interaction --dev "doctrine/mongodb-odm" "doctrine/mongodb-odm-bundle" composer update --prefer-dist install-lowest: setup @@ -24,10 +23,13 @@ install-highest: composer config minimum-stability dev composer update -install-odm: - rm -f composer.lock - composer require --no-interaction --dev "doctrine/mongodb-odm:^2.2" "doctrine/mongodb-odm-bundle:^4.3" - composer update --prefer-dist +add-odm: + composer require --no-update --no-interaction --dev "doctrine/mongodb-odm:^2.2" "doctrine/mongodb-odm-bundle:^4.3" + @echo "Run again appropriate install target to update dependencies" + +remove-odm: + composer remove --no-update --no-interaction --dev "doctrine/mongodb-odm" "doctrine/mongodb-odm-bundle" + @echo "Run again appropriate install target to update dependencies" ######## # Test # diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractCsvCollectionEnumType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractCsvCollectionEnumType.php index d77047d5..e1aa10c9 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractCsvCollectionEnumType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractCsvCollectionEnumType.php @@ -16,6 +16,9 @@ abstract class AbstractCsvCollectionEnumType extends SimpleArrayType { + /** + * @return mixed + */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (\is_array($value)) { @@ -27,6 +30,9 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return parent::convertToDatabaseValue($value, $platform); } + /** + * @return mixed + */ public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php index b1503d75..d3fd044f 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php @@ -20,7 +20,7 @@ abstract class AbstractEnumSQLDeclarationType extends AbstractEnumType /** * {@inheritdoc} */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { $values = implode(', ', array_map(static function (string $value): string { return "'$value'"; diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php index 2f0b877c..75056606 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php @@ -52,6 +52,8 @@ protected function onNullFromPhp() * * @param EnumInterface|null $value * @psalm-param T|null $value + * + * @return mixed */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { @@ -64,6 +66,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) /** * {@inheritdoc} + * + * @return mixed */ public function convertToPHPValue($value, AbstractPlatform $platform) { @@ -79,7 +83,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) /** * {@inheritdoc} */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); } @@ -95,7 +99,7 @@ public function getDefaultLength(AbstractPlatform $platform) /** * {@inheritdoc} */ - public function requiresSQLCommentHint(AbstractPlatform $platform) + public function requiresSQLCommentHint(AbstractPlatform $platform): bool { return true; } diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractIntegerEnumType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractIntegerEnumType.php index 01357665..a0c27d38 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractIntegerEnumType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractIntegerEnumType.php @@ -17,7 +17,7 @@ abstract class AbstractIntegerEnumType extends AbstractEnumType /** * {@inheritdoc} */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration); } @@ -25,7 +25,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla /** * {@inheritdoc} */ - public function getBindingType() + public function getBindingType(): int { return \PDO::PARAM_INT; } diff --git a/src/Bridge/Doctrine/DBAL/Types/AbstractJsonCollectionEnumType.php b/src/Bridge/Doctrine/DBAL/Types/AbstractJsonCollectionEnumType.php index aa67a3b8..526cdb3e 100644 --- a/src/Bridge/Doctrine/DBAL/Types/AbstractJsonCollectionEnumType.php +++ b/src/Bridge/Doctrine/DBAL/Types/AbstractJsonCollectionEnumType.php @@ -16,6 +16,9 @@ abstract class AbstractJsonCollectionEnumType extends JsonType { + /** + * @return mixed + */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (\is_array($value)) { @@ -27,6 +30,9 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return parent::convertToDatabaseValue($value, $platform); } + /** + * @return mixed + */ public function convertToPHPValue($value, AbstractPlatform $platform) { $values = parent::convertToPHPValue($value, $platform); @@ -41,7 +47,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) /** * {@inheritdoc} */ - public function requiresSQLCommentHint(AbstractPlatform $platform) + public function requiresSQLCommentHint(AbstractPlatform $platform): bool { return true; } diff --git a/src/Bridge/Doctrine/ODM/Types/AbstractCollectionEnumType.php b/src/Bridge/Doctrine/ODM/Types/AbstractCollectionEnumType.php index d22ae5b9..60824681 100644 --- a/src/Bridge/Doctrine/ODM/Types/AbstractCollectionEnumType.php +++ b/src/Bridge/Doctrine/ODM/Types/AbstractCollectionEnumType.php @@ -21,6 +21,9 @@ abstract class AbstractCollectionEnumType extends CollectionType { use ClosureToPHP; + /** + * @return mixed + */ public function convertToDatabaseValue($value) { if (\is_array($value)) { @@ -36,6 +39,8 @@ public function convertToDatabaseValue($value) * {@inheritdoc} * * @psalm-return array|null + * + * @return mixed */ public function convertToPHPValue($value) { diff --git a/src/Bridge/Doctrine/ODM/Types/AbstractEnumType.php b/src/Bridge/Doctrine/ODM/Types/AbstractEnumType.php index 290083f7..1f94f03d 100644 --- a/src/Bridge/Doctrine/ODM/Types/AbstractEnumType.php +++ b/src/Bridge/Doctrine/ODM/Types/AbstractEnumType.php @@ -23,6 +23,8 @@ abstract class AbstractEnumType extends Type /** * {@inheritdoc} + * + * @return mixed */ public function convertToDatabaseValue($value) { diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php index 5064d8f7..58ef0b76 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php @@ -20,7 +20,7 @@ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('elao_enum'); $rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('elao_enum'); diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/ElaoEnumExtension.php b/src/Bridge/Symfony/Bundle/DependencyInjection/ElaoEnumExtension.php index 5f50f703..cc8ab8a4 100644 --- a/src/Bridge/Symfony/Bundle/DependencyInjection/ElaoEnumExtension.php +++ b/src/Bridge/Symfony/Bundle/DependencyInjection/ElaoEnumExtension.php @@ -103,12 +103,12 @@ public function load(array $configs, ContainerBuilder $container) ; } - public function getNamespace() + public function getNamespace(): string { return 'http://elao.com/schema/dic/elao_enum'; } - public function getXsdValidationBasePath() + public function getXsdValidationBasePath(): string { return __DIR__ . '/../Resources/config/schema'; } diff --git a/src/Bridge/Symfony/Console/Command/DumpJsEnumsCommand.php b/src/Bridge/Symfony/Console/Command/DumpJsEnumsCommand.php index 18c7835d..2197007d 100644 --- a/src/Bridge/Symfony/Console/Command/DumpJsEnumsCommand.php +++ b/src/Bridge/Symfony/Console/Command/DumpJsEnumsCommand.php @@ -53,7 +53,7 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); diff --git a/src/Bridge/Symfony/Form/Type/EnumType.php b/src/Bridge/Symfony/Form/Type/EnumType.php index 7f46b995..ad0f42fc 100644 --- a/src/Bridge/Symfony/Form/Type/EnumType.php +++ b/src/Bridge/Symfony/Form/Type/EnumType.php @@ -20,6 +20,9 @@ use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; +/** + * @final + */ class EnumType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) @@ -102,7 +105,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getParent() + public function getParent(): ?string { return ChoiceType::class; } diff --git a/src/Bridge/Symfony/Form/Type/FlaggedEnumType.php b/src/Bridge/Symfony/Form/Type/FlaggedEnumType.php index 1770e403..1f54c8ba 100644 --- a/src/Bridge/Symfony/Form/Type/FlaggedEnumType.php +++ b/src/Bridge/Symfony/Form/Type/FlaggedEnumType.php @@ -18,6 +18,9 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +/** + * @final + */ class FlaggedEnumType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) @@ -53,7 +56,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getParent() + public function getParent(): ?string { return EnumType::class; } diff --git a/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/EnumValueResolver.php b/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/EnumValueResolver.php index 92044d70..6adbc28f 100644 --- a/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/EnumValueResolver.php +++ b/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/EnumValueResolver.php @@ -16,12 +16,15 @@ use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +/** + * @final + */ class EnumValueResolver implements ArgumentValueResolverInterface { /** * {@inheritdoc} */ - public function supports(Request $request, ArgumentMetadata $argument) + public function supports(Request $request, ArgumentMetadata $argument): bool { return is_subclass_of($argument->getType(), EnumInterface::class); } @@ -29,7 +32,7 @@ public function supports(Request $request, ArgumentMetadata $argument) /** * {@inheritdoc} */ - public function resolve(Request $request, ArgumentMetadata $argument) + public function resolve(Request $request, ArgumentMetadata $argument): iterable { /** @var EnumInterface $enumClass */ $enumClass = $argument->getType(); diff --git a/src/Bridge/Symfony/Serializer/Normalizer/EnumNormalizer.php b/src/Bridge/Symfony/Serializer/Normalizer/EnumNormalizer.php index 53ce52bc..b4411ad3 100644 --- a/src/Bridge/Symfony/Serializer/Normalizer/EnumNormalizer.php +++ b/src/Bridge/Symfony/Serializer/Normalizer/EnumNormalizer.php @@ -16,6 +16,9 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +/** + * @final + */ class EnumNormalizer implements NormalizerInterface, DenormalizerInterface { /** @@ -23,7 +26,7 @@ class EnumNormalizer implements NormalizerInterface, DenormalizerInterface * * @param EnumInterface $object */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, $format = null, array $context = []): string { return $object->getValue(); } @@ -31,7 +34,7 @@ public function normalize($object, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = null) + public function supportsNormalization($data, $format = null): bool { return $data instanceof EnumInterface; } @@ -39,7 +42,7 @@ public function supportsNormalization($data, $format = null) /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = null, array $context = []) + public function denormalize($data, $class, $format = null, array $context = []): EnumInterface { try { return \call_user_func([$class, 'get'], $data); @@ -51,7 +54,7 @@ public function denormalize($data, $class, $format = null, array $context = []) /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null) + public function supportsDenormalization($data, $type, $format = null): bool { return is_a($type, EnumInterface::class, true); } diff --git a/src/Bridge/Symfony/Validator/Constraint/Enum.php b/src/Bridge/Symfony/Validator/Constraint/Enum.php index c1802455..71c3cd9f 100644 --- a/src/Bridge/Symfony/Validator/Constraint/Enum.php +++ b/src/Bridge/Symfony/Validator/Constraint/Enum.php @@ -107,6 +107,8 @@ public function __construct( /** * {@inheritdoc} + * + * @return string */ public function validatedBy() { @@ -115,6 +117,8 @@ public function validatedBy() /** * {@inheritdoc} + * + * @return string|null */ public function getDefaultOption() { @@ -123,6 +127,8 @@ public function getDefaultOption() /** * {@inheritdoc} + * + * @return string[] */ public function getRequiredOptions() { diff --git a/src/Bridge/Twig/Extension/EnumExtension.php b/src/Bridge/Twig/Extension/EnumExtension.php index 49ee1a9c..da6bccc3 100644 --- a/src/Bridge/Twig/Extension/EnumExtension.php +++ b/src/Bridge/Twig/Extension/EnumExtension.php @@ -18,7 +18,10 @@ class EnumExtension extends AbstractExtension { - public function getFunctions() + /** + * {@inheritdoc} + */ + public function getFunctions(): array { return [ new TwigFunction('enum_get', [$this, 'get']), diff --git a/src/Enum.php b/src/Enum.php index 5e50ad95..79acbdd0 100644 --- a/src/Enum.php +++ b/src/Enum.php @@ -159,6 +159,7 @@ public function is($value): bool /** * @return T */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return $this->getValue(); diff --git a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/GenderEnumType.php b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/GenderEnumType.php index 137d554f..b9a31cbc 100644 --- a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/GenderEnumType.php +++ b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/GenderEnumType.php @@ -32,7 +32,7 @@ protected function onNullFromPhp() return Gender::UNKNOW; } - public function getName() + public function getName(): string { return self::NAME; } diff --git a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleCsvCollectionEnumType.php b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleCsvCollectionEnumType.php index c8bcc41d..eaff6f62 100644 --- a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleCsvCollectionEnumType.php +++ b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleCsvCollectionEnumType.php @@ -22,7 +22,7 @@ protected function getEnumClass(): string return SimpleEnum::class; } - public function getName() + public function getName(): string { return self::NAME; } diff --git a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleEnumType.php b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleEnumType.php index 50a76824..f6c8e892 100644 --- a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleEnumType.php +++ b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleEnumType.php @@ -32,7 +32,7 @@ protected function onNullFromPhp() return SimpleEnum::ZERO; } - public function getName() + public function getName(): string { return self::NAME; } diff --git a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleJsonCollectionEnumType.php b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleJsonCollectionEnumType.php index 6b146063..e1e3332f 100644 --- a/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleJsonCollectionEnumType.php +++ b/tests/Fixtures/Bridge/Doctrine/DBAL/Types/SimpleJsonCollectionEnumType.php @@ -22,7 +22,7 @@ protected function getEnumClass(): string return SimpleEnum::class; } - public function getName() + public function getName(): string { return self::NAME; } diff --git a/tests/Fixtures/Integration/Symfony/src/Kernel.php b/tests/Fixtures/Integration/Symfony/src/Kernel.php index 115f60f9..9ca531ae 100644 --- a/tests/Fixtures/Integration/Symfony/src/Kernel.php +++ b/tests/Fixtures/Integration/Symfony/src/Kernel.php @@ -23,7 +23,7 @@ */ class Kernel extends BaseKernel { - public function registerBundles() + public function registerBundles(): iterable { return array_filter([ new FrameworkBundle(), @@ -49,7 +49,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) } } - public function getProjectDir() + public function getProjectDir(): string { return __DIR__ . '/../'; }