Skip to content

Commit

Permalink
Replace squizlabs/php_codesniffer by symplify/easy-coding-standard
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Ben87 committed Aug 18, 2024
1 parent b4adb15 commit a88f314
Show file tree
Hide file tree
Showing 37 changed files with 235 additions and 160 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
branches: ['*']

jobs:
phpcs:
name: 'PHP CodeSniffer'
ecs:
name: 'Easy Coding Standard'
runs-on: 'ubuntu-latest'

strategy:
Expand All @@ -26,8 +26,8 @@ jobs:
- name: 'Install dependencies'
run: 'composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist'

- name: 'Execute PHP CodeSniffer'
run: 'vendor/bin/phpcs'
- name: 'Execute Easy Coding Standard'
run: 'vendor/bin/ecs'

phpstan:
name: 'PHPStan'
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/docker/
/var/
/vendor/
/.phpcs-cache
/.phpunit.result.cache
/composer.lock
/Taskfile.yaml
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"doctrine/orm": "^3.2.1",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^10.5|^11.3",
"squizlabs/php_codesniffer": "^3.10",
"symfony/console": "^6.0|^7.0",
"symfony/dotenv": "^6.0|^7.0",
"symfony/framework-bundle": "^6.0|^7.0",
"symfony/phpunit-bridge": "^6.0|^7.0",
"symfony/runtime": "^6.0|^7.0",
"symfony/var-dumper": "^6.0|^7.0",
"symfony/yaml": "^6.0|^7.0"
"symfony/yaml": "^6.0|^7.0",
"symplify/easy-coding-standard": "^12.3"
},
"autoload": {
"psr-4": {
Expand Down
94 changes: 94 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use Presta\BehatEvaluator\Adapter\ScalarAdapter;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths(
[
__DIR__ . '/src',
__DIR__ . '/tests',
],
)
->withPreparedSets(
psr12: true,
arrays: true,
comments: true,
docblocks: true,
namespaces: true,
phpunit: true,
strict: true,
)
->withConfiguredRule(
BlankLineBeforeStatementFixer::class,
[
'statements' => ['case', 'continue', 'declare', 'default', 'return', 'throw', 'try'],
],
)
->withConfiguredRule(
CastSpacesFixer::class,
[
'space' => 'none',
],
)
->withConfiguredRule(
ForbiddenFunctionsSniff::class,
[
'forbiddenFunctions' => ['dump' => null, 'dd' => null, 'var_dump' => null, 'die' => null],
],
)
->withConfiguredRule(
LineLengthFixer::class,
[
LineLengthFixer::INLINE_SHORT_LINES => false,
],
)
->withConfiguredRule(
NativeFunctionInvocationFixer::class,
[
'scope' => 'namespaced',
'include' => ['@all'],
],
)
->withConfiguredRule(
NullableTypeDeclarationFixer::class,
[
'syntax' => 'union',
],
)
->withConfiguredRule(
YodaStyleFixer::class,
[
'equal' => true,
'identical' => true,
'less_and_greater' => false,
],
)
->withRules([
FunctionDeclarationFixer::class,
])
->withSkip(
[
ArrayListItemNewlineFixer::class,
ArrayOpenerAndCloserNewlineFixer::class,
ExplicitStringVariableFixer::class,
StandaloneLineInMultilineArrayFixer::class,
StrictComparisonFixer::class => [
'src/Adapter/ScalarAdapter.php',
],
],
)
;
17 changes: 0 additions & 17 deletions phpcs.xml.dist

This file was deleted.

8 changes: 4 additions & 4 deletions src/Adapter/ConstantAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function __invoke(mixed $value): mixed
$evaluated = $this->expressionLanguage->evaluate($expression);

// the evaluation did not end up with a transformation
preg_match('/constant\([\'"](?<value>[^)]+)[\'"]\)/', $expression, $expressionMatches);
if (\is_string($evaluated) && $expressionMatches['value'] === addslashes($evaluated)) {
\preg_match('/constant\([\'"](?<value>[^)]+)[\'"]\)/', $expression, $expressionMatches);
if (\is_string($evaluated) && $expressionMatches['value'] === \addslashes($evaluated)) {
continue;
}

Expand All @@ -41,13 +41,13 @@ public function __invoke(mixed $value): mixed
}

if (!\is_scalar($evaluated) && !$evaluated instanceof \Stringable) {
$type = get_debug_type($evaluated);
$type = \get_debug_type($evaluated);

throw new \RuntimeException("The evaluated constant of type \"$type\" could not be cast to string.");
}

// the expression is included in a larger string
$value = str_replace("<$expression>", (string) $evaluated, $value);
$value = \str_replace("<$expression>", (string)$evaluated, $value);
}

return $value;
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/DateTimeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function __invoke(mixed $value): mixed
// surround named parameters arguments by double quotes
// so that the named parameter part is not interpreted by the expression language
// ex. 'format: "Y-m-d"' will be transformed to '"format: \"Y-m-d\""'
$quotedExpression = preg_replace_callback(
$quotedExpression = \preg_replace_callback(
'/(format|intl): ?[^,)]+/',
static function (array $matches): string {
$value = addslashes($matches[0] ?? '');
$value = \addslashes($matches[0] ?? '');

return "\"$value\"";
},
Expand All @@ -62,7 +62,7 @@ static function (array $matches): string {

\assert(\is_string($evaluated));

$value = str_replace("<$expression>", $evaluated, $value);
$value = \str_replace("<$expression>", $evaluated, $value);
}

return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/EnumAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __invoke(mixed $value): mixed

\assert(\is_int($evaluated) || \is_string($evaluated));

$value = str_replace("<$expression>", (string)$evaluated, $value);
$value = \str_replace("<$expression>", (string)$evaluated, $value);
}

return match (\is_numeric($value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/FactoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __invoke(mixed $value): mixed
throw new \RuntimeException();
}

$value = str_replace("<$expression>", (string) $evaluated, $value);
$value = \str_replace("<$expression>", (string)$evaluated, $value);
}

return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/JsonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __invoke(mixed $value): mixed
return $value;
}

$data = json_decode($value, true);
$data = \json_decode($value, true);
if (\is_array($data)) {
return $data;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/NthAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public function __invoke(mixed $value): mixed
return $value;
}

preg_match('/^(?<count>\d+)(st|nd|rd|th)$/', $value, $matches);
\preg_match('/^(?<count>\d+)(st|nd|rd|th)$/', $value, $matches);
if ('' === ($matches['count'] ?? '')) {
return $value;
}

return (int) $matches['count'];
return (int)$matches['count'];
}
}
4 changes: 2 additions & 2 deletions src/Adapter/ScalarAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function __invoke(mixed $value): mixed
'null' === $value => null,
'true' === $value => true,
'false' === $value => false,
(int) $value == $value => (int) $value,
(float) $value == $value => (float) $value,
(int)$value == $value => (int)$value,
(float)$value == $value => (float)$value,
default => $value,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/UnescapeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function __invoke(mixed $value): mixed
return $value;
}

return stripslashes($value);
return \stripslashes($value);
}
}
2 changes: 1 addition & 1 deletion src/Evaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function evaluate(mixed $value, EvaluatorBuilder $builder = new Ev
*/
public static function evaluateMany(array $values, EvaluatorBuilder $builder = new EvaluatorBuilder()): array
{
return array_map(
return \array_map(
static fn (mixed $value): mixed => self::evaluate($value, $builder),
$values,
);
Expand Down
24 changes: 12 additions & 12 deletions src/EvaluatorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ public function __construct()
$this->inflector = InflectorFactory::create()->build();
$this->registerAdapterFactory(
ConstantAdapter::class,
static fn(ExpressionLanguage $expressionLanguage): AdapterInterface
static fn (ExpressionLanguage $expressionLanguage): AdapterInterface
=> new ConstantAdapter($expressionLanguage),
);
$this->registerAdapterFactory(
DateTimeAdapter::class,
static fn(ExpressionLanguage $expressionLanguage): AdapterInterface
static fn (ExpressionLanguage $expressionLanguage): AdapterInterface
=> new DateTimeAdapter($expressionLanguage),
);
$this->registerAdapterFactory(
EnumAdapter::class,
static fn(ExpressionLanguage $expressionLanguage): AdapterInterface
static fn (ExpressionLanguage $expressionLanguage): AdapterInterface
=> new EnumAdapter($expressionLanguage),
);
$this->registerAdapterFactory(
FactoryAdapter::class,
static fn(ExpressionLanguage $expressionLanguage): AdapterInterface
static fn (ExpressionLanguage $expressionLanguage): AdapterInterface
=> new FactoryAdapter($expressionLanguage),
);
$this->registerAdapterFactory(JsonAdapter::class, static fn(): AdapterInterface => new JsonAdapter());
$this->registerAdapterFactory(NthAdapter::class, static fn(): AdapterInterface => new NthAdapter());
$this->registerAdapterFactory(ScalarAdapter::class, static fn(): AdapterInterface => new ScalarAdapter());
$this->registerAdapterFactory(UnescapeAdapter::class, static fn(): AdapterInterface => new UnescapeAdapter());
$this->registerAdapterFactory(JsonAdapter::class, static fn (): AdapterInterface => new JsonAdapter());
$this->registerAdapterFactory(NthAdapter::class, static fn (): AdapterInterface => new NthAdapter());
$this->registerAdapterFactory(ScalarAdapter::class, static fn (): AdapterInterface => new ScalarAdapter());
$this->registerAdapterFactory(UnescapeAdapter::class, static fn (): AdapterInterface => new UnescapeAdapter());
}

/**
Expand All @@ -67,7 +67,7 @@ public function __construct()
*/
public function registerAdapter(AdapterInterface $adapter): self
{
$this->adapterFactories[$adapter::class] = static fn(): AdapterInterface => $adapter;
$this->adapterFactories[$adapter::class] = static fn (): AdapterInterface => $adapter;

return $this;
}
Expand Down Expand Up @@ -122,9 +122,9 @@ public function build(): Evaluator
);

return new Evaluator(
array_values(
array_map(
static fn(\Closure $factory): AdapterInterface => $factory($expressionLanguage),
\array_values(
\array_map(
static fn (\Closure $factory): AdapterInterface => $factory($expressionLanguage),
$this->adapterFactories,
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnexpectedTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class UnexpectedTypeException extends \RuntimeException
{
public function __construct(mixed $value, string $expectedType)
{
$actualType = get_debug_type($value);
$actualType = \get_debug_type($value);

parent::__construct("Expected argument of type \"$expectedType\", \"$actualType\" given.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ public function __invoke(string|array|null $time = null, string|array|null $form
}

/**
* @param string $argument
*
* @return IntlFormats|string
*/
private function format(string $argument): array|string
{
$argument = trim(str_replace(['format:', 'intl:'], '', $argument), ' "\'');
$argument = \trim(\str_replace(['format:', 'intl:'], '', $argument), ' "\'');

try {
/** @var IntlFormats $formats */
$formats = json_decode($argument, true, JSON_THROW_ON_ERROR);
$formats = \json_decode($argument, true, JSON_THROW_ON_ERROR);
if (\is_array($formats)) {
return $formats;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ExpressionLanguage/Evaluator/ConstantEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class ConstantEvaluator
public function __invoke(array $arguments, string $value): mixed
{
try {
return constant($value);
return \constant($value);
} catch (\Throwable) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/ExpressionLanguage/Evaluator/DateTimeEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public function __invoke(array $arguments, string|array|null $time = null, strin
private function intl(\DateTimeInterface $datetime, array $formats): string
{
$date = $formats['date'] ?? 'NONE';
$date = constant("\IntlDateFormatter::$date");
$date = \constant("\IntlDateFormatter::$date");
if (!\is_int($date)) {
throw new \RuntimeException('The intl date format should be a valid \IntlDateFormatter format');
}

$time = $formats['time'] ?? 'NONE';
$time = constant("\IntlDateFormatter::$time");
$time = \constant("\IntlDateFormatter::$time");
if (!\is_int($time)) {
throw new \RuntimeException('The intl time format should be a valid \IntlDateFormatter format');
}
Expand Down
Loading

0 comments on commit a88f314

Please sign in to comment.