Skip to content

Commit e19f95f

Browse files
committed
Fixed code style issues with enhanced symplify/easy-coding-standard config
1 parent 21da4d8 commit e19f95f

35 files changed

+62
-207
lines changed

src/ConstantExtractor.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
final class ConstantExtractor
1717
{
1818
/**
19-
* @param string $pattern
20-
*
21-
* @return array
2219
* @throws LogicException
2320
*/
2421
public static function extract(string $pattern): array
@@ -34,21 +31,21 @@ public static function extract(string $pattern): array
3431

3532
private static function filter(array $constants, string $regexp, string $pattern): array
3633
{
37-
$matchingNames = preg_grep($regexp, array_keys($constants));
34+
$matchingNames = \preg_grep($regexp, \array_keys($constants));
3835

39-
if (count($matchingNames) === 0) {
36+
if (\count($matchingNames) === 0) {
4037
throw LogicException::cannotExtractConstants($pattern, 'Pattern matches no constant.');
4138
}
4239

43-
return array_values(array_intersect_key($constants, array_flip($matchingNames)));
40+
return \array_values(\array_intersect_key($constants, \array_flip($matchingNames)));
4441
}
4542

4643
private static function publicConstants(string $class, string $pattern): array
4744
{
4845
try {
4946
$constants = (new ReflectionClass($class))->getReflectionConstants();
5047
} catch (ReflectionException $exception) {
51-
throw LogicException::cannotExtractConstants($pattern, sprintf('Class %s does not exists.', $class));
48+
throw LogicException::cannotExtractConstants($pattern, \sprintf('Class %s does not exists.', $class));
5249
}
5350

5451
$list = [];
@@ -60,34 +57,37 @@ private static function publicConstants(string $class, string $pattern): array
6057
$list[$constant->getName()] = $constant->getValue();
6158
}
6259

63-
if (count($list) === 0) {
64-
throw LogicException::cannotExtractConstants($pattern, sprintf('Class %s has no public constant.', $class));
60+
if (\count($list) === 0) {
61+
throw LogicException::cannotExtractConstants(
62+
$pattern,
63+
\sprintf('Class %s has no public constant.', $class)
64+
);
6565
}
6666

6767
return $list;
6868
}
6969

7070
private static function explode(string $pattern): array
7171
{
72-
if (substr_count($pattern, '::') !== 1) {
72+
if (\substr_count($pattern, '::') !== 1) {
7373
throw LogicException::cannotExtractConstants(
7474
$pattern,
7575
'Pattern must look like Fully\\Qualified\\ClassName::CONSTANT_*.'
7676
);
7777
}
7878

79-
[$class, $constantsNamePattern] = explode('::', $pattern);
79+
[$class, $constantsNamePattern] = \explode('::', $pattern);
8080

81-
if (substr_count($constantsNamePattern, '*') === 0) {
81+
if (\substr_count($constantsNamePattern, '*') === 0) {
8282
throw LogicException::cannotExtractConstants(
8383
$pattern,
8484
'Pattern must look like Fully\\Qualified\\ClassName::CONSTANT_*.'
8585
);
8686
}
8787

88-
$constantsNameRegexp = sprintf(
88+
$constantsNameRegexp = \sprintf(
8989
'#^%s$#',
90-
str_replace('*', '[0-9a-zA-Z_]+', $constantsNamePattern)
90+
\str_replace('*', '[0-9a-zA-Z_]+', $constantsNamePattern)
9191
);
9292

9393
return [$class, $constantsNameRegexp];

src/ConstantListEnum.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
*/
1010
class ConstantListEnum extends Enum
1111
{
12-
/**
13-
* @param string $constantsPattern
14-
* @param string|null $name
15-
*/
1612
public function __construct(string $constantsPattern, ?string $name = null)
1713
{
1814
$values = ConstantExtractor::extract($constantsPattern);
19-
parent::__construct(array_combine($values, $values), $name);
15+
parent::__construct(\array_combine($values, $values), $name);
2016
}
2117
}

src/ConstantListTranslatedEnum.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
*/
1212
class ConstantListTranslatedEnum extends TranslatedEnum
1313
{
14-
/**
15-
* @param string $constantsPattern
16-
* @param TranslatorInterface $translator
17-
* @param string $transPattern
18-
* @param string $transDomain
19-
* @param string|null $name
20-
*/
2114
public function __construct(
2215
string $constantsPattern,
2316
TranslatorInterface $translator,

src/DependencyInjection/CompilerPass/TaggedEnumCollectorCompilerPass.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
*/
1414
final class TaggedEnumCollectorCompilerPass implements CompilerPassInterface
1515
{
16-
/**
17-
* @inheritdoc
18-
*/
1916
public function process(ContainerBuilder $container): void
2017
{
2118
if (!$container->hasDefinition('yokai_enum.enum_registry')) {
@@ -24,7 +21,7 @@ public function process(ContainerBuilder $container): void
2421

2522
$registry = $container->getDefinition('yokai_enum.enum_registry');
2623

27-
foreach (array_keys($container->findTaggedServiceIds('yokai_enum.enum')) as $enum) {
24+
foreach (\array_keys($container->findTaggedServiceIds('yokai_enum.enum')) as $enum) {
2825
$registry->addMethodCall('add', [new Reference($enum)]);
2926
}
3027
}

src/DependencyInjection/EnumExtension.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@
2222
*/
2323
final class EnumExtension extends Extension
2424
{
25-
/**
26-
* @inheritdoc
27-
*/
2825
public function load(array $configs, ContainerBuilder $container): void
2926
{
3027
$container->register('yokai_enum.enum_registry', EnumRegistry::class);
3128
$container->setAlias(EnumRegistry::class, 'yokai_enum.enum_registry');
3229

3330
$registry = new Reference(EnumRegistry::class);
3431

35-
$requiresForm = interface_exists(FormInterface::class);
36-
$requiresValidator = interface_exists(ValidatorInterface::class);
37-
$requiresTwig = class_exists(TwigBundle::class);
32+
$requiresForm = \interface_exists(FormInterface::class);
33+
$requiresValidator = \interface_exists(ValidatorInterface::class);
34+
$requiresTwig = \class_exists(TwigBundle::class);
3835

3936
if ($requiresForm) {
4037
$container->register('yokai_enum.form_type.enum_type', EnumType::class)

src/Enum.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Enum implements EnumInterface
3030
*/
3131
public function __construct(?array $choices, ?string $name = null)
3232
{
33-
if (__CLASS__ === static::class && $choices === null) {
33+
if (static::class === __CLASS__ && $choices === null) {
3434
throw new LogicException(
3535
'When using ' . __CLASS__ . ' directly, $choices argument in ' . __FUNCTION__ . ' method cannot be null'
3636
);
@@ -53,44 +53,32 @@ public function __construct(?array $choices, ?string $name = null)
5353
$this->name = $name;
5454
}
5555

56-
/**
57-
* @inheritDoc
58-
*/
5956
public function getChoices(): array
6057
{
6158
$this->init();
6259

6360
return $this->choices;
6461
}
6562

66-
/**
67-
* @inheritDoc
68-
*/
6963
public function getValues(): array
7064
{
7165
$this->init();
7266

7367
return \array_values($this->choices);
7468
}
7569

76-
/**
77-
* @inheritDoc
78-
*/
7970
public function getLabel($value): string
8071
{
8172
$this->init();
8273

83-
$label = \array_search($value, $this->choices);
74+
$label = \array_search($value, $this->choices, true);
8475
if ($label === false) {
8576
throw InvalidArgumentException::enumMissingValue($this, $value);
8677
}
8778

8879
return $label;
8980
}
9081

91-
/**
92-
* @inheritDoc
93-
*/
9482
public function getName(): string
9583
{
9684
return $this->name;

src/EnumInterface.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ public function getValues(): array;
2727
* Returns enum value label.
2828
*
2929
* @param mixed $value
30-
*
31-
* @return string
3230
*/
3331
public function getLabel($value): string;
3432

3533
/**
3634
* Returns enum identifier (must be unique across app).
37-
*
38-
* @return string
3935
*/
4036
public function getName(): string;
4137
}

src/EnumRegistry.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ final class EnumRegistry
1818
private $enums = [];
1919

2020
/**
21-
* @param EnumInterface $enum
22-
*
2321
* @throws LogicException
2422
*/
2523
public function add(EnumInterface $enum): void
@@ -32,9 +30,6 @@ public function add(EnumInterface $enum): void
3230
}
3331

3432
/**
35-
* @param string $name
36-
*
37-
* @return EnumInterface
3833
* @throws InvalidArgumentException
3934
*/
4035
public function get(string $name): EnumInterface
@@ -46,11 +41,6 @@ public function get(string $name): EnumInterface
4641
return $this->enums[$name];
4742
}
4843

49-
/**
50-
* @param string $name
51-
*
52-
* @return bool
53-
*/
5444
public function has(string $name): bool
5545
{
5646
return isset($this->enums[$name]);

src/Exception/InvalidArgumentException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ final class InvalidArgumentException extends \InvalidArgumentException implement
1313
{
1414
public static function unregisteredEnum(string $name): self
1515
{
16-
return new self(sprintf(
16+
return new self(\sprintf(
1717
'Enum with name "%s" was not registered in registry',
1818
$name
1919
));
2020
}
2121

2222
public static function enumMissingValue(EnumInterface $enum, string $value): self
2323
{
24-
return new self(sprintf(
24+
return new self(\sprintf(
2525
'Enum "%s" does not have "%s" value.',
2626
$enum->getName(),
2727
$value

src/Exception/LogicException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ public static function cannotExtractConstants(string $pattern, string $reason):
1717

1818
public static function placeholderRequired(string $transPattern): self
1919
{
20-
return new self(sprintf(
20+
return new self(\sprintf(
2121
'Translation pattern "%s" must contain %%s placeholder.',
2222
$transPattern
2323
));
2424
}
2525

2626
public static function alreadyRegistered(string $name): self
2727
{
28-
return new self(sprintf(
28+
return new self(\sprintf(
2929
'Enum with name "%s" is already registered.',
3030
$name
3131
));
3232
}
3333

3434
public static function invalidMyClabsEnumClass(string $enum): self
3535
{
36-
return new self(sprintf(
36+
return new self(\sprintf(
3737
'Enum class must be valid "myclabs/php-enum" enum class. Got "%s".',
3838
$enum
3939
));
4040
}
4141

4242
public static function invalidUnitEnum(string $enum): self
4343
{
44-
return new self(sprintf(
44+
return new self(\sprintf(
4545
'Enum class must be valid PHP enum. Got "%s".',
4646
$enum
4747
));

0 commit comments

Comments
 (0)