diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index fec36e4..1b802f6 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -86,5 +86,5 @@ jobs:
- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
- - name: "Run checkstyle with squizlabs/php_codesniffer"
- run: vendor/bin/phpcs
+ - name: "Run checkstyle with symplify/easy-coding-standard"
+ run: vendor/bin/ecs
diff --git a/composer.json b/composer.json
index 3ad69b1..2404e8b 100644
--- a/composer.json
+++ b/composer.json
@@ -17,13 +17,13 @@
"doctrine/annotations": "^1.14",
"myclabs/php-enum": "^1.8",
"phpunit/phpunit": "^9.6",
- "squizlabs/php_codesniffer": "^3.10",
"symfony/form": "^7.0",
"symfony/http-kernel": "^7.0",
"symfony/translation": "^7.0",
"symfony/twig-bundle": "^7.0",
"symfony/validator": "^7.0",
"symfony/yaml": "^7.0",
+ "symplify/easy-coding-standard": "^12.3",
"twig/twig": "^2.0|^3.0"
},
"suggest": {
diff --git a/ecs.php b/ecs.php
new file mode 100644
index 0000000..eee8619
--- /dev/null
+++ b/ecs.php
@@ -0,0 +1,58 @@
+paths([
+ __DIR__ . '/src',
+ __DIR__ . '/tests/Integration/src',
+ __DIR__ . '/tests/Integration/tests',
+ __DIR__ . '/tests/Unit',
+ ]);
+
+ $ecsConfig->sets([
+ SetList::ARRAY,
+ SetList::DOCBLOCK,
+ SetList::NAMESPACES,
+ SetList::COMMENTS,
+ SetList::STRICT,
+ SetList::PSR_12,
+ ]);
+
+ $ecsConfig->skip([
+ /* Do not force array on multiple lines : ['foo' => $foo, 'bar' => $bar] */
+ ArrayOpenerAndCloserNewlineFixer::class,
+ ArrayListItemNewlineFixer::class,
+ StandaloneLineInMultilineArrayFixer::class,
+ ]);
+
+ $ecsConfig->ruleWithConfiguration(YodaStyleFixer::class, [
+ 'equal' => false,
+ 'identical' => false,
+ 'less_and_greater' => false,
+ ]);
+ $ecsConfig->ruleWithConfiguration(LineLengthFixer::class, [
+ LineLengthFixer::INLINE_SHORT_LINES => false,
+ ]);
+ $ecsConfig->ruleWithConfiguration(ForbiddenFunctionsSniff::class, [
+ 'forbiddenFunctions' => ['dump' => null, 'dd' => null, 'var_dump' => null, 'die' => null],
+ ]);
+ $ecsConfig->ruleWithConfiguration(FunctionDeclarationFixer::class, [
+ 'closure_fn_spacing' => 'none',
+ ]);
+ $ecsConfig->ruleWithConfiguration(NativeFunctionInvocationFixer::class, [
+ 'scope' => 'namespaced',
+ 'include' => ['@all'],
+ ]);
+};
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
deleted file mode 100644
index 02a5f78..0000000
--- a/phpcs.xml.dist
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
- src/
- tests/Integration/src/
- tests/Integration/tests/
- tests/Unit/
-
-
-
-
-
-
-
-
-
diff --git a/src/ConstantExtractor.php b/src/ConstantExtractor.php
index 620ecd5..bbe2fd3 100644
--- a/src/ConstantExtractor.php
+++ b/src/ConstantExtractor.php
@@ -16,9 +16,6 @@
final class ConstantExtractor
{
/**
- * @param string $pattern
- *
- * @return array
* @throws LogicException
*/
public static function extract(string $pattern): array
@@ -34,13 +31,13 @@ public static function extract(string $pattern): array
private static function filter(array $constants, string $regexp, string $pattern): array
{
- $matchingNames = preg_grep($regexp, array_keys($constants));
+ $matchingNames = \preg_grep($regexp, \array_keys($constants));
- if (count($matchingNames) === 0) {
+ if (\count($matchingNames) === 0) {
throw LogicException::cannotExtractConstants($pattern, 'Pattern matches no constant.');
}
- return array_values(array_intersect_key($constants, array_flip($matchingNames)));
+ return \array_values(\array_intersect_key($constants, \array_flip($matchingNames)));
}
private static function publicConstants(string $class, string $pattern): array
@@ -48,7 +45,7 @@ private static function publicConstants(string $class, string $pattern): array
try {
$constants = (new ReflectionClass($class))->getReflectionConstants();
} catch (ReflectionException $exception) {
- throw LogicException::cannotExtractConstants($pattern, sprintf('Class %s does not exists.', $class));
+ throw LogicException::cannotExtractConstants($pattern, \sprintf('Class %s does not exists.', $class));
}
$list = [];
@@ -60,8 +57,11 @@ private static function publicConstants(string $class, string $pattern): array
$list[$constant->getName()] = $constant->getValue();
}
- if (count($list) === 0) {
- throw LogicException::cannotExtractConstants($pattern, sprintf('Class %s has no public constant.', $class));
+ if (\count($list) === 0) {
+ throw LogicException::cannotExtractConstants(
+ $pattern,
+ \sprintf('Class %s has no public constant.', $class)
+ );
}
return $list;
@@ -69,25 +69,25 @@ private static function publicConstants(string $class, string $pattern): array
private static function explode(string $pattern): array
{
- if (substr_count($pattern, '::') !== 1) {
+ if (\substr_count($pattern, '::') !== 1) {
throw LogicException::cannotExtractConstants(
$pattern,
'Pattern must look like Fully\\Qualified\\ClassName::CONSTANT_*.'
);
}
- [$class, $constantsNamePattern] = explode('::', $pattern);
+ [$class, $constantsNamePattern] = \explode('::', $pattern);
- if (substr_count($constantsNamePattern, '*') === 0) {
+ if (\substr_count($constantsNamePattern, '*') === 0) {
throw LogicException::cannotExtractConstants(
$pattern,
'Pattern must look like Fully\\Qualified\\ClassName::CONSTANT_*.'
);
}
- $constantsNameRegexp = sprintf(
+ $constantsNameRegexp = \sprintf(
'#^%s$#',
- str_replace('*', '[0-9a-zA-Z_]+', $constantsNamePattern)
+ \str_replace('*', '[0-9a-zA-Z_]+', $constantsNamePattern)
);
return [$class, $constantsNameRegexp];
diff --git a/src/ConstantListEnum.php b/src/ConstantListEnum.php
index 37522dd..c7b601b 100644
--- a/src/ConstantListEnum.php
+++ b/src/ConstantListEnum.php
@@ -9,13 +9,9 @@
*/
class ConstantListEnum extends Enum
{
- /**
- * @param string $constantsPattern
- * @param string|null $name
- */
public function __construct(string $constantsPattern, ?string $name = null)
{
$values = ConstantExtractor::extract($constantsPattern);
- parent::__construct(array_combine($values, $values), $name);
+ parent::__construct(\array_combine($values, $values), $name);
}
}
diff --git a/src/ConstantListTranslatedEnum.php b/src/ConstantListTranslatedEnum.php
index 3c57b7c..3a7b137 100644
--- a/src/ConstantListTranslatedEnum.php
+++ b/src/ConstantListTranslatedEnum.php
@@ -11,13 +11,6 @@
*/
class ConstantListTranslatedEnum extends TranslatedEnum
{
- /**
- * @param string $constantsPattern
- * @param TranslatorInterface $translator
- * @param string $transPattern
- * @param string $transDomain
- * @param string|null $name
- */
public function __construct(
string $constantsPattern,
TranslatorInterface $translator,
diff --git a/src/DependencyInjection/CompilerPass/TaggedEnumCollectorCompilerPass.php b/src/DependencyInjection/CompilerPass/TaggedEnumCollectorCompilerPass.php
index 3738eae..069988d 100644
--- a/src/DependencyInjection/CompilerPass/TaggedEnumCollectorCompilerPass.php
+++ b/src/DependencyInjection/CompilerPass/TaggedEnumCollectorCompilerPass.php
@@ -13,9 +13,6 @@
*/
final class TaggedEnumCollectorCompilerPass implements CompilerPassInterface
{
- /**
- * @inheritdoc
- */
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('yokai_enum.enum_registry')) {
@@ -24,7 +21,7 @@ public function process(ContainerBuilder $container): void
$registry = $container->getDefinition('yokai_enum.enum_registry');
- foreach (array_keys($container->findTaggedServiceIds('yokai_enum.enum')) as $enum) {
+ foreach (\array_keys($container->findTaggedServiceIds('yokai_enum.enum')) as $enum) {
$registry->addMethodCall('add', [new Reference($enum)]);
}
}
diff --git a/src/DependencyInjection/EnumExtension.php b/src/DependencyInjection/EnumExtension.php
index 3ef00ae..9244f57 100644
--- a/src/DependencyInjection/EnumExtension.php
+++ b/src/DependencyInjection/EnumExtension.php
@@ -22,9 +22,6 @@
*/
final class EnumExtension extends Extension
{
- /**
- * @inheritdoc
- */
public function load(array $configs, ContainerBuilder $container): void
{
$container->register('yokai_enum.enum_registry', EnumRegistry::class);
@@ -32,9 +29,9 @@ public function load(array $configs, ContainerBuilder $container): void
$registry = new Reference(EnumRegistry::class);
- $requiresForm = interface_exists(FormInterface::class);
- $requiresValidator = interface_exists(ValidatorInterface::class);
- $requiresTwig = class_exists(TwigBundle::class);
+ $requiresForm = \interface_exists(FormInterface::class);
+ $requiresValidator = \interface_exists(ValidatorInterface::class);
+ $requiresTwig = \class_exists(TwigBundle::class);
if ($requiresForm) {
$container->register('yokai_enum.form_type.enum_type', EnumType::class)
diff --git a/src/Enum.php b/src/Enum.php
index 4ab2999..a50ef86 100644
--- a/src/Enum.php
+++ b/src/Enum.php
@@ -30,7 +30,7 @@ class Enum implements EnumInterface
*/
public function __construct(?array $choices, ?string $name = null)
{
- if (__CLASS__ === static::class && $choices === null) {
+ if (static::class === __CLASS__ && $choices === null) {
throw new LogicException(
'When using ' . __CLASS__ . ' directly, $choices argument in ' . __FUNCTION__ . ' method cannot be null'
);
@@ -53,9 +53,6 @@ public function __construct(?array $choices, ?string $name = null)
$this->name = $name;
}
- /**
- * @inheritDoc
- */
public function getChoices(): array
{
$this->init();
@@ -63,9 +60,6 @@ public function getChoices(): array
return $this->choices;
}
- /**
- * @inheritDoc
- */
public function getValues(): array
{
$this->init();
@@ -73,14 +67,11 @@ public function getValues(): array
return \array_values($this->choices);
}
- /**
- * @inheritDoc
- */
public function getLabel($value): string
{
$this->init();
- $label = \array_search($value, $this->choices);
+ $label = \array_search($value, $this->choices, false);
if ($label === false) {
throw InvalidArgumentException::enumMissingValue($this, $value);
}
@@ -88,9 +79,6 @@ public function getLabel($value): string
return $label;
}
- /**
- * @inheritDoc
- */
public function getName(): string
{
return $this->name;
diff --git a/src/EnumInterface.php b/src/EnumInterface.php
index cbdbd4c..3bc727e 100644
--- a/src/EnumInterface.php
+++ b/src/EnumInterface.php
@@ -27,15 +27,11 @@ public function getValues(): array;
* Returns enum value label.
*
* @param mixed $value
- *
- * @return string
*/
public function getLabel($value): string;
/**
* Returns enum identifier (must be unique across app).
- *
- * @return string
*/
public function getName(): string;
}
diff --git a/src/EnumRegistry.php b/src/EnumRegistry.php
index 27c150d..64116c7 100644
--- a/src/EnumRegistry.php
+++ b/src/EnumRegistry.php
@@ -18,8 +18,6 @@ final class EnumRegistry
private $enums = [];
/**
- * @param EnumInterface $enum
- *
* @throws LogicException
*/
public function add(EnumInterface $enum): void
@@ -32,9 +30,6 @@ public function add(EnumInterface $enum): void
}
/**
- * @param string $name
- *
- * @return EnumInterface
* @throws InvalidArgumentException
*/
public function get(string $name): EnumInterface
@@ -46,11 +41,6 @@ public function get(string $name): EnumInterface
return $this->enums[$name];
}
- /**
- * @param string $name
- *
- * @return bool
- */
public function has(string $name): bool
{
return isset($this->enums[$name]);
diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php
index 62fa18f..6f90d40 100644
--- a/src/Exception/InvalidArgumentException.php
+++ b/src/Exception/InvalidArgumentException.php
@@ -13,15 +13,22 @@ final class InvalidArgumentException extends \InvalidArgumentException implement
{
public static function unregisteredEnum(string $name): self
{
- return new self(sprintf(
+ return new self(\sprintf(
'Enum with name "%s" was not registered in registry',
$name
));
}
- public static function enumMissingValue(EnumInterface $enum, string $value): self
+ public static function enumMissingValue(EnumInterface $enum, mixed $value): self
{
- return new self(sprintf(
+ if (\is_object($value) && \method_exists($value, '__toString')) {
+ $value = (string)$value;
+ }
+ if (!\is_string($value)) {
+ $value = \get_debug_type($value);
+ }
+
+ return new self(\sprintf(
'Enum "%s" does not have "%s" value.',
$enum->getName(),
$value
diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php
index 126738f..f1be5dd 100644
--- a/src/Exception/LogicException.php
+++ b/src/Exception/LogicException.php
@@ -17,7 +17,7 @@ public static function cannotExtractConstants(string $pattern, string $reason):
public static function placeholderRequired(string $transPattern): self
{
- return new self(sprintf(
+ return new self(\sprintf(
'Translation pattern "%s" must contain %%s placeholder.',
$transPattern
));
@@ -25,7 +25,7 @@ public static function placeholderRequired(string $transPattern): self
public static function alreadyRegistered(string $name): self
{
- return new self(sprintf(
+ return new self(\sprintf(
'Enum with name "%s" is already registered.',
$name
));
@@ -33,7 +33,7 @@ public static function alreadyRegistered(string $name): self
public static function invalidMyClabsEnumClass(string $enum): self
{
- return new self(sprintf(
+ return new self(\sprintf(
'Enum class must be valid "myclabs/php-enum" enum class. Got "%s".',
$enum
));
@@ -41,7 +41,7 @@ public static function invalidMyClabsEnumClass(string $enum): self
public static function invalidUnitEnum(string $enum): self
{
- return new self(sprintf(
+ return new self(\sprintf(
'Enum class must be valid PHP enum. Got "%s".',
$enum
));
diff --git a/src/Form/Extension/EnumTypeGuesser.php b/src/Form/Extension/EnumTypeGuesser.php
index bd29494..fa2cf6e 100644
--- a/src/Form/Extension/EnumTypeGuesser.php
+++ b/src/Form/Extension/EnumTypeGuesser.php
@@ -18,9 +18,6 @@
*/
final class EnumTypeGuesser extends ValidatorTypeGuesser
{
- /**
- * @inheritdoc
- */
public function guessTypeForConstraint(Constraint $constraint): ?TypeGuess
{
$enum = $this->getEnum($constraint);
@@ -38,25 +35,16 @@ public function guessTypeForConstraint(Constraint $constraint): ?TypeGuess
);
}
- /**
- * @inheritDoc
- */
public function guessRequired($class, $property): ?ValueGuess
{
return null; //override parent : not able to guess
}
- /**
- * @inheritDoc
- */
public function guessMaxLength($class, $property): ?ValueGuess
{
return null; //override parent : not able to guess
}
- /**
- * @inheritDoc
- */
public function guessPattern($class, $property): ?ValueGuess
{
return null; //override parent : not able to guess
diff --git a/src/Form/Type/EnumType.php b/src/Form/Type/EnumType.php
index 6c8e800..cb918ec 100644
--- a/src/Form/Type/EnumType.php
+++ b/src/Form/Type/EnumType.php
@@ -21,17 +21,11 @@ final class EnumType extends AbstractType
*/
private $enumRegistry;
- /**
- * @param EnumRegistry $enumRegistry
- */
public function __construct(EnumRegistry $enumRegistry)
{
$this->enumRegistry = $enumRegistry;
}
- /**
- * @inheritdoc
- */
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
@@ -91,17 +85,11 @@ static function (Options $options) {
;
}
- /**
- * @inheritdoc
- */
public function getParent(): string
{
return ChoiceType::class;
}
- /**
- * @inheritdoc
- */
public function getBlockPrefix(): string
{
return 'yokai_enum';
diff --git a/src/MyCLabsEnum.php b/src/MyCLabsEnum.php
index 2b95ddd..bf26639 100644
--- a/src/MyCLabsEnum.php
+++ b/src/MyCLabsEnum.php
@@ -12,10 +12,6 @@
*/
class MyCLabsEnum extends Enum
{
- /**
- * @param string $enum
- * @param string|null $name
- */
public function __construct(string $enum, string $name = null)
{
if (!\is_a($enum, ActualMyCLabsEnum::class, true)) {
diff --git a/src/MyCLabsTranslatedEnum.php b/src/MyCLabsTranslatedEnum.php
index 0723236..8d5c883 100644
--- a/src/MyCLabsTranslatedEnum.php
+++ b/src/MyCLabsTranslatedEnum.php
@@ -13,13 +13,6 @@
*/
class MyCLabsTranslatedEnum extends TranslatedEnum
{
- /**
- * @param string $enum
- * @param TranslatorInterface $translator
- * @param string $transPattern
- * @param string $transDomain
- * @param string|null $name
- */
public function __construct(
string $enum,
TranslatorInterface $translator,
diff --git a/src/NativeEnum.php b/src/NativeEnum.php
index afffaed..3dcb69b 100644
--- a/src/NativeEnum.php
+++ b/src/NativeEnum.php
@@ -12,10 +12,6 @@
*/
class NativeEnum extends Enum
{
- /**
- * @param string $enum
- * @param string|null $name
- */
public function __construct(string $enum, string $name = null)
{
if (!\is_a($enum, UnitEnum::class, true)) {
diff --git a/src/NativeTranslatedEnum.php b/src/NativeTranslatedEnum.php
index 9ad2274..4121dea 100644
--- a/src/NativeTranslatedEnum.php
+++ b/src/NativeTranslatedEnum.php
@@ -4,8 +4,8 @@
namespace Yokai\EnumBundle;
-use UnitEnum;
use Symfony\Contracts\Translation\TranslatorInterface;
+use UnitEnum;
use Yokai\EnumBundle\Exception\LogicException;
/**
@@ -13,13 +13,6 @@
*/
class NativeTranslatedEnum extends TranslatedEnum
{
- /**
- * @param string $enum
- * @param TranslatorInterface $translator
- * @param string $transPattern
- * @param string $transDomain
- * @param string|null $name
- */
public function __construct(
string $enum,
TranslatorInterface $translator,
diff --git a/src/TranslatedEnum.php b/src/TranslatedEnum.php
index 635117a..76bde36 100644
--- a/src/TranslatedEnum.php
+++ b/src/TranslatedEnum.php
@@ -34,10 +34,6 @@ class TranslatedEnum extends Enum
/**
* @param array $values
- * @param TranslatorInterface $translator
- * @param string $transPattern
- * @param string $transDomain
- * @param string|null $name
*
* @throws LogicException
*/
@@ -48,7 +44,7 @@ public function __construct(
string $transDomain = 'messages',
?string $name = null
) {
- if (false === strpos($transPattern, '%s')) {
+ if (\strpos($transPattern, '%s') === false) {
throw LogicException::placeholderRequired($transPattern);
}
@@ -60,9 +56,6 @@ public function __construct(
parent::__construct(null, $name);
}
- /**
- * @inheritdoc
- */
protected function build(): array
{
$choices = [];
diff --git a/src/Twig/Extension/EnumExtension.php b/src/Twig/Extension/EnumExtension.php
index 45b61a5..0cdf2d6 100644
--- a/src/Twig/Extension/EnumExtension.php
+++ b/src/Twig/Extension/EnumExtension.php
@@ -19,17 +19,11 @@ final class EnumExtension extends AbstractExtension
*/
private $registry;
- /**
- * @param EnumRegistry $registry
- */
public function __construct(EnumRegistry $registry)
{
$this->registry = $registry;
}
- /**
- * @inheritdoc
- */
public function getFunctions(): array
{
return [
@@ -42,9 +36,6 @@ public function getFunctions(): array
];
}
- /**
- * @inheritdoc
- */
public function getFilters(): array
{
return [
diff --git a/src/Validator/Constraints/Enum.php b/src/Validator/Constraints/Enum.php
index 61444dc..3cfe2db 100644
--- a/src/Validator/Constraints/Enum.php
+++ b/src/Validator/Constraints/Enum.php
@@ -84,17 +84,11 @@ public function __construct(
}
}
- /**
- * @inheritdoc
- */
public function getDefaultOption(): string
{
return 'enum';
}
- /**
- * @inheritdoc
- */
public function validatedBy(): string
{
return 'yokai_enum.validator_constraints.enum_validator';
diff --git a/src/Validator/Constraints/EnumValidator.php b/src/Validator/Constraints/EnumValidator.php
index 4c1df42..05773f1 100644
--- a/src/Validator/Constraints/EnumValidator.php
+++ b/src/Validator/Constraints/EnumValidator.php
@@ -20,24 +20,18 @@ final class EnumValidator extends ChoiceValidator
*/
private $enumRegistry;
- /**
- * @param EnumRegistry $enumRegistry
- */
public function __construct(EnumRegistry $enumRegistry)
{
$this->enumRegistry = $enumRegistry;
}
- /**
- * @inheritdoc
- */
public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof Enum) {
throw new UnexpectedTypeException($constraint, Enum::class);
}
- $constraint->choices = null;
+ $constraint->choices = null;
$constraint->callback = null;
if (!$constraint->enum) {
@@ -45,7 +39,7 @@ public function validate($value, Constraint $constraint): void
}
if (!$this->enumRegistry->has($constraint->enum)) {
- throw new ConstraintDefinitionException(sprintf(
+ throw new ConstraintDefinitionException(\sprintf(
'"enum" "%s" on constraint Enum does not exist',
$constraint->enum
));
diff --git a/src/YokaiEnumBundle.php b/src/YokaiEnumBundle.php
index 189578a..875d71c 100644
--- a/src/YokaiEnumBundle.php
+++ b/src/YokaiEnumBundle.php
@@ -14,9 +14,6 @@
*/
final class YokaiEnumBundle extends Bundle
{
- /**
- * @inheritdoc
- */
public function build(ContainerBuilder $container): void
{
$container
@@ -24,9 +21,6 @@ public function build(ContainerBuilder $container): void
;
}
- /**
- * @inheritdoc
- */
public function getContainerExtension(): EnumExtension
{
return new EnumExtension();
diff --git a/tests/Integration/src/Kernel.php b/tests/Integration/src/Kernel.php
index 1c3ff39..c3b7670 100644
--- a/tests/Integration/src/Kernel.php
+++ b/tests/Integration/src/Kernel.php
@@ -43,13 +43,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
}
}
- /**
- * @inheritDoc
- */
protected function build(ContainerBuilder $container): void
{
$container->addCompilerPass(
- new class implements CompilerPassInterface {
+ new class() implements CompilerPassInterface {
public function process(ContainerBuilder $container)
{
$container->findDefinition('form.factory')->setPublic(true);
diff --git a/tests/Integration/src/Model/PullRequestPhp7.php b/tests/Integration/src/Model/PullRequestPhp7.php
index 960569b..1f6ae37 100644
--- a/tests/Integration/src/Model/PullRequestPhp7.php
+++ b/tests/Integration/src/Model/PullRequestPhp7.php
@@ -4,9 +4,9 @@
namespace Yokai\EnumBundle\Tests\Integration\App\Model;
-use Yokai\EnumBundle\Validator\Constraints\Enum;
-use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestMyCLabsStatusEnum;
use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestLabelEnum;
+use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestMyCLabsStatusEnum;
+use Yokai\EnumBundle\Validator\Constraints\Enum;
/**
* @author Yann Eugoné
diff --git a/tests/Integration/src/Model/PullRequestPhp80.php b/tests/Integration/src/Model/PullRequestPhp80.php
index 6f05417..1f86dfb 100644
--- a/tests/Integration/src/Model/PullRequestPhp80.php
+++ b/tests/Integration/src/Model/PullRequestPhp80.php
@@ -4,9 +4,9 @@
namespace Yokai\EnumBundle\Tests\Integration\App\Model;
-use Yokai\EnumBundle\Validator\Constraints\Enum;
-use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestMyCLabsStatusEnum;
use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestLabelEnum;
+use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestMyCLabsStatusEnum;
+use Yokai\EnumBundle\Validator\Constraints\Enum;
/**
* @author Yann Eugoné
diff --git a/tests/Integration/src/Model/PullRequestPhp81.php b/tests/Integration/src/Model/PullRequestPhp81.php
index 2f4a715..b8aed16 100644
--- a/tests/Integration/src/Model/PullRequestPhp81.php
+++ b/tests/Integration/src/Model/PullRequestPhp81.php
@@ -4,9 +4,9 @@
namespace Yokai\EnumBundle\Tests\Integration\App\Model;
-use Yokai\EnumBundle\Validator\Constraints\Enum;
-use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestNativeStatusEnum;
use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestLabelEnum;
+use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestNativeStatusEnum;
+use Yokai\EnumBundle\Validator\Constraints\Enum;
/**
* @author Yann Eugoné
diff --git a/tests/Integration/tests/PullRequestFormTest.php b/tests/Integration/tests/PullRequestFormTest.php
index 3190416..c4a27f2 100644
--- a/tests/Integration/tests/PullRequestFormTest.php
+++ b/tests/Integration/tests/PullRequestFormTest.php
@@ -15,10 +15,10 @@
use Yokai\EnumBundle\Tests\Integration\App\Enum\PullRequestNativeStatusEnum;
use Yokai\EnumBundle\Tests\Integration\App\Form\PullRequestType;
use Yokai\EnumBundle\Tests\Integration\App\Kernel;
+use Yokai\EnumBundle\Tests\Integration\App\Model\MyCLabsStatus;
use Yokai\EnumBundle\Tests\Integration\App\Model\NativeStatus;
use Yokai\EnumBundle\Tests\Integration\App\Model\PullRequestPhp7;
use Yokai\EnumBundle\Tests\Integration\App\Model\PullRequestPhp80;
-use Yokai\EnumBundle\Tests\Integration\App\Model\MyCLabsStatus;
use Yokai\EnumBundle\Tests\Integration\App\Model\PullRequestPhp81;
/**
@@ -96,13 +96,13 @@ public function valid(): Generator
yield [
['status' => 0, 'labels' => ['bugfix', '1.x']],
self::pullRequest(),
- self::pullRequest('opened', ['bugfix', '1.x'])
+ self::pullRequest('opened', ['bugfix', '1.x']),
];
yield [
['status' => 2, 'labels' => ['bugfix', '2.x']],
self::pullRequest('opened', ['bugfix', '1.x']),
- self::pullRequest('closed', ['bugfix', '2.x'])
+ self::pullRequest('closed', ['bugfix', '2.x']),
];
}
@@ -123,7 +123,7 @@ public function testSubmitInvalidData(array $formData, $model, array $errors): v
$formErrors = $form->get($path)->getErrors();
self::assertCount(1, $formErrors);
/** @var ConstraintViolationInterface $violation */
- $violation = $formErrors[0]->getCause();
+ $violation = $formErrors[0]->getCause();
self::assertSame($message, $violation->getMessage());
}
}
@@ -138,13 +138,13 @@ public function invalid(): Generator
yield [
['status' => 3, 'labels' => ['bugfix', '5.x']],
self::pullRequest(),
- ['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.']
+ ['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.'],
];
yield [
['status' => 3, 'labels' => ['bugfix', '5.x']],
self::pullRequest('opened', ['bugfix', '1.x']),
- ['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.']
+ ['status' => $message, 'labels' => 'The choices "5.x" do not exist in the choice list.'],
];
}
@@ -184,7 +184,7 @@ private static function pullRequest(string $status = null, array $labels = [])
private static function form(ContainerInterface $container, $model): FormInterface
{
- $class = get_class(self::pullRequest());
+ $class = \get_class(self::pullRequest());
return $container->get('form.factory')
->create(PullRequestType::class, $model, ['data_class' => $class]);
diff --git a/tests/Unit/DependencyInjection/EnumExtensionTest.php b/tests/Unit/DependencyInjection/EnumExtensionTest.php
index 4f44370..4aefc55 100644
--- a/tests/Unit/DependencyInjection/EnumExtensionTest.php
+++ b/tests/Unit/DependencyInjection/EnumExtensionTest.php
@@ -27,7 +27,7 @@ public function testLoad(): void
'yokai_enum.twig_extension.enum_extension',
];
foreach ($services as $service) {
- self::assertTrue($container->has($service), sprintf('Service "%s" is registered', $service));
+ self::assertTrue($container->has($service), \sprintf('Service "%s" is registered', $service));
}
$autoconfigure = $container->getAutoconfiguredInstanceof();
diff --git a/tests/Unit/EnumTest.php b/tests/Unit/EnumTest.php
index 82a780c..8fed9e5 100644
--- a/tests/Unit/EnumTest.php
+++ b/tests/Unit/EnumTest.php
@@ -62,7 +62,7 @@ public function testEnumMustHaveName(): void
public function testInheritedEnumMustHaveChoicesOrBuildMethod(): void
{
$this->expectException(LogicException::class);
- $fooEnum = new class (null, 'foo') extends Enum {
+ $fooEnum = new class(null, 'foo') extends Enum {
};
$fooEnum->getLabel('something');
}
diff --git a/tests/Unit/EnumsFromFixturesTest.php b/tests/Unit/EnumsFromFixturesTest.php
index 2a5c52b..00b2755 100644
--- a/tests/Unit/EnumsFromFixturesTest.php
+++ b/tests/Unit/EnumsFromFixturesTest.php
@@ -46,19 +46,19 @@ public function enums(): Generator
'action.EDIT' => 'Modifier',
])),
ActionEnum::class,
- ['Voir' => Action::VIEW(), 'Modifier' => Action::EDIT()]
+ ['Voir' => Action::VIEW(), 'Modifier' => Action::EDIT()],
];
yield StateEnum::class . ' : direct interface implementation' => [
new StateEnum(),
StateEnum::class,
- ['New' => 'new', 'Validated' => 'validated', 'Disabled' => 'disabled']
+ ['New' => 'new', 'Validated' => 'validated', 'Disabled' => 'disabled'],
];
yield StatusEnum::class . ' : myclabs/php-enum enum' => [
new StatusEnum(),
StatusEnum::class,
- ['SUCCESS' => Status::SUCCESS(), 'ERROR' => Status::ERROR()]
+ ['SUCCESS' => Status::SUCCESS(), 'ERROR' => Status::ERROR()],
];
yield SubscriptionEnum::class . ' : translated enum with keyword name' => [
@@ -69,13 +69,13 @@ public function enums(): Generator
'choice.subscription.monthly' => 'Mensuelle',
])),
'subscription',
- ['Aucune' => 'none', 'Journalière' => 'daily', 'Hebdomadaire' => 'weekly', 'Mensuelle' => 'monthly']
+ ['Aucune' => 'none', 'Journalière' => 'daily', 'Hebdomadaire' => 'weekly', 'Mensuelle' => 'monthly'],
];
yield TypeEnum::class . ' : enum with keyword name' => [
new TypeEnum(),
'type',
- ['Customer' => 'customer', 'Prospect' => 'prospect']
+ ['Customer' => 'customer', 'Prospect' => 'prospect'],
];
yield VehicleBrandEnum::class . ' : constant list enum with keyword name' => [
diff --git a/tests/Unit/Fixtures/StateEnum.php b/tests/Unit/Fixtures/StateEnum.php
index f160e24..8ff51f6 100644
--- a/tests/Unit/Fixtures/StateEnum.php
+++ b/tests/Unit/Fixtures/StateEnum.php
@@ -16,37 +16,25 @@
*/
class StateEnum implements EnumInterface
{
- /**
- * @inheritDoc
- */
public function getName(): string
{
return __CLASS__;
}
- /**
- * @inheritDoc
- */
public function getValues(): array
{
return \array_values($this->getChoices());
}
- /**
- * @inheritDoc
- */
public function getChoices(): array
{
return ['New' => 'new', 'Validated' => 'validated', 'Disabled' => 'disabled'];
}
- /**
- * @inheritdoc
- */
public function getLabel($value): string
{
$choices = $this->getChoices();
- $label = \array_search($value, $choices);
+ $label = \array_search($value, $choices, true);
if ($label === false) {
throw InvalidArgumentException::enumMissingValue($this, $value);
}
diff --git a/tests/Unit/Form/Extension/EnumTypeGuesserTest.php b/tests/Unit/Form/Extension/EnumTypeGuesserTest.php
index ebc301f..2e5302a 100644
--- a/tests/Unit/Form/Extension/EnumTypeGuesserTest.php
+++ b/tests/Unit/Form/Extension/EnumTypeGuesserTest.php
@@ -54,10 +54,10 @@ protected function setUp(): void
$metadata = new ClassMetadata(self::TEST_CLASS);
$metadata->addPropertyConstraint(self::TEST_PROPERTY_NONE, new Choice(['choices' => ['new', 'validated']]));
$metadata->addPropertyConstraint(self::TEST_PROPERTY_DIRECT, new Enum(['enum' => StateEnum::class]));
- if (class_exists(Compound::class)) {
+ if (\class_exists(Compound::class)) {
$metadata->addPropertyConstraint(
self::TEST_PROPERTY_COMPOUND,
- new class extends Compound {
+ new class() extends Compound {
protected function getConstraints(array $options): array
{
return [new Enum(['enum' => StateEnum::class])];
@@ -91,7 +91,7 @@ public function testGuessTypeDirect(): void
public function testGuessTypeCompound(): void
{
- if (!class_exists(Compound::class)) {
+ if (!\class_exists(Compound::class)) {
$this->markTestSkipped();
}
diff --git a/tests/Unit/Form/TestExtension.php b/tests/Unit/Form/TestExtension.php
index e58d67b..7f71df3 100644
--- a/tests/Unit/Form/TestExtension.php
+++ b/tests/Unit/Form/TestExtension.php
@@ -25,19 +25,12 @@ class TestExtension extends AbstractExtension
*/
private $metadataFactory;
- /**
- * @param EnumRegistry $enumRegistry
- * @param MetadataFactoryInterface|null $metadataFactory
- */
public function __construct(EnumRegistry $enumRegistry, MetadataFactoryInterface $metadataFactory = null)
{
$this->enumRegistry = $enumRegistry;
$this->metadataFactory = $metadataFactory;
}
- /**
- * @inheritdoc
- */
protected function loadTypes(): array
{
return [
@@ -45,9 +38,6 @@ protected function loadTypes(): array
];
}
- /**
- * @inheritdoc
- */
protected function loadTypeGuesser(): ?EnumTypeGuesser
{
if ($this->metadataFactory === null) {
diff --git a/tests/Unit/Form/Type/EnumTypeTest.php b/tests/Unit/Form/Type/EnumTypeTest.php
index e4f89f8..5009386 100644
--- a/tests/Unit/Form/Type/EnumTypeTest.php
+++ b/tests/Unit/Form/Type/EnumTypeTest.php
@@ -144,7 +144,7 @@ protected function getExtensions(): array
}
return [
- new TestExtension($enumRegistry)
+ new TestExtension($enumRegistry),
];
}
diff --git a/tests/Unit/Translator.php b/tests/Unit/Translator.php
index cae83e7..f1a71a0 100644
--- a/tests/Unit/Translator.php
+++ b/tests/Unit/Translator.php
@@ -1,4 +1,5 @@
createTemplate(<<createTemplate(
+ <<render([])
@@ -66,7 +67,8 @@ public function testEnumValues(): void
self::assertSame(
'new|validated|disabled|',
- $twig->createTemplate(<<createTemplate(
+ <<render([])