Skip to content

Commit

Permalink
Fix 5.4 deprecs & types
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Oct 26, 2021
1 parent 9440cbd commit 51bf36d
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 39 deletions.
19 changes: 10 additions & 9 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
;
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

abstract class AbstractCsvCollectionEnumType extends SimpleArrayType
{
/**
* @return mixed
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (\is_array($value)) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'";
Expand Down
8 changes: 6 additions & 2 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected function onNullFromPhp()
*
* @param EnumInterface|null $value
* @psalm-param T|null $value
*
* @return mixed
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
Expand All @@ -64,6 +66,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

/**
* {@inheritdoc}
*
* @return mixed
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
Expand All @@ -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);
}
Expand All @@ -95,7 +99,7 @@ public function getDefaultLength(AbstractPlatform $platform)
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Doctrine/DBAL/Types/AbstractIntegerEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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);
}

/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType(): int
{
return \PDO::PARAM_INT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

abstract class AbstractJsonCollectionEnumType extends JsonType
{
/**
* @return mixed
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (\is_array($value)) {
Expand All @@ -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);
Expand All @@ -41,7 +47,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Bridge/Doctrine/ODM/Types/AbstractCollectionEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ abstract class AbstractCollectionEnumType extends CollectionType
{
use ClosureToPHP;

/**
* @return mixed
*/
public function convertToDatabaseValue($value)
{
if (\is_array($value)) {
Expand All @@ -36,6 +39,8 @@ public function convertToDatabaseValue($value)
* {@inheritdoc}
*
* @psalm-return array<TEnum>|null
*
* @return mixed
*/
public function convertToPHPValue($value)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/Doctrine/ODM/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract class AbstractEnumType extends Type

/**
* {@inheritdoc}
*
* @return mixed
*/
public function convertToDatabaseValue($value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Console/Command/DumpJsEnumsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion src/Bridge/Symfony/Form/Type/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -102,7 +105,7 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): ?string
{
return ChoiceType::class;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Bridge/Symfony/Form/Type/FlaggedEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -53,7 +56,7 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): ?string
{
return EnumType::class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
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);
}

/**
* {@inheritdoc}
*/
public function resolve(Request $request, ArgumentMetadata $argument)
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
/** @var EnumInterface $enumClass */
$enumClass = $argument->getType();
Expand Down
11 changes: 7 additions & 4 deletions src/Bridge/Symfony/Serializer/Normalizer/EnumNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* @final
*/
class EnumNormalizer implements NormalizerInterface, DenormalizerInterface
{
/**
* {@inheritdoc}
*
* @param EnumInterface $object
*/
public function normalize($object, $format = null, array $context = [])
public function normalize($object, $format = null, array $context = []): string
{
return $object->getValue();
}

/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization($data, $format = null): bool
{
return $data instanceof EnumInterface;
}

/**
* {@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);
Expand All @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Bridge/Symfony/Validator/Constraint/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function __construct(

/**
* {@inheritdoc}
*
* @return string
*/
public function validatedBy()
{
Expand All @@ -115,6 +117,8 @@ public function validatedBy()

/**
* {@inheritdoc}
*
* @return string|null
*/
public function getDefaultOption()
{
Expand All @@ -123,6 +127,8 @@ public function getDefaultOption()

/**
* {@inheritdoc}
*
* @return string[]
*/
public function getRequiredOptions()
{
Expand Down
5 changes: 4 additions & 1 deletion src/Bridge/Twig/Extension/EnumExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

class EnumExtension extends AbstractExtension
{
public function getFunctions()
/**
* {@inheritdoc}
*/
public function getFunctions(): array
{
return [
new TwigFunction('enum_get', [$this, 'get']),
Expand Down
1 change: 1 addition & 0 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function is($value): bool
/**
* @return T
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function onNullFromPhp()
return Gender::UNKNOW;
}

public function getName()
public function getName(): string
{
return self::NAME;
}
Expand Down
Loading

0 comments on commit 51bf36d

Please sign in to comment.