diff --git a/.gitattributes b/.gitattributes index 3629c57..d4fba32 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ /.gitattributes export-ignore /.github export-ignore /.gitignore export-ignore -/.php-cs-fixer.dist.php export-ignore +/ecs.php export-ignore /phpstan.neon.dist export-ignore /phpstan-baseline.neon export-ignore /phpunit.xml.dist export-ignore diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index ab0b5c9..b48edfb 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -7,8 +7,8 @@ on: branches: ['1.x'] jobs: - php-cs-fixer: - name: PHP CS Fixer (PHP ${{ matrix.php-version }}) + easy-coding-standard: + name: Easy Coding Standard (PHP ${{ matrix.php-version }}) runs-on: ubuntu-24.04 strategy: @@ -31,5 +31,5 @@ jobs: - name: Install Composer dependencies uses: ramsey/composer-install@v3 - - name: Run PHP CS Fixer - run: 'vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr' + - name: Run Easy Coding Standard + run: 'vendor/bin/ecs --output-format=checkstyle | cs2pr' diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 99ff0c2..325c608 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -23,12 +23,12 @@ jobs: symfony-version: - '6.4.*' - '7.3.*' - - '7.4.x-dev' + - '7.4.*@dev' include: - php-version: '8.4' - symfony-version: '8.0.x-dev' + symfony-version: '8.0.*@dev' - php-version: '8.5' - symfony-version: '8.0.x-dev' + symfony-version: '8.0.*@dev' steps: - name: Checkout code diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 53ee2d0..0000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,44 +0,0 @@ -in(__DIR__ . '/src') - ->in(__DIR__ . '/tests') -; - -return (new PhpCsFixer\Config()) - ->setRiskyAllowed(true) - ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'no_unneeded_final_method' => false, - 'dir_constant' => true, - 'modernize_types_casting' => true, - 'echo_tag_syntax' => ['format' => 'long'], - 'no_useless_else' => true, - 'no_useless_return' => true, - 'native_function_invocation' => ['include' => ['@compiler_optimized']], - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_construct' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => [ - 'operators' => [ - '=>' => 'align_single_space', - ], - ], - 'concat_space' => ['spacing' => 'one'], - 'semicolon_after_instruction' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'yoda_style' => [ - 'always_move_variable' => true, - 'equal' => true, - 'identical' => true, - 'less_and_greater' => true, - ], - 'declare_strict_types' => true, - ]) - ->setFinder($finder) - ->setCacheFile(__DIR__.'/.php_cs.cache') -; diff --git a/composer.json b/composer.json index e5838f9..89a05cf 100644 --- a/composer.json +++ b/composer.json @@ -31,13 +31,13 @@ "twig/twig": "^3.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.86.0", "phpstan/phpstan": "^2.1.22", "phpstan/phpstan-deprecation-rules": "^2.0.3", "phpunit/phpunit": "^11.5.35", "symfony/css-selector": "^6.4 || ^7.0 || ^8.0", "symfony/dom-crawler": "^6.4 || ^7.0 || ^8.0", - "symfony/yaml": "^6.4 || ^7.0 || ^8.0" + "symfony/yaml": "^6.4 || ^7.0 || ^8.0", + "symplify/easy-coding-standard": "^12.5.24" }, "scripts": { "ci": [ @@ -45,8 +45,8 @@ "@phpstan", "vendor/bin/phpunit --colors=auto" ], - "cs:dry": "php-cs-fixer fix --diff --dry-run --no-interaction --ansi", - "cs:fix": "php-cs-fixer fix --ansi", + "cs:dry": "vendor/bin/ecs", + "cs:fix": "vendor/bin/ecs --fix", "phpstan": "vendor/bin/phpstan analyse --ansi" }, "autoload": { diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..df680e1 --- /dev/null +++ b/ecs.php @@ -0,0 +1,28 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withRootFiles() + ->withRules([ + NoUselessElseFixer::class, + NoUselessReturnFixer::class, + StrictComparisonFixer::class, + StrictParamFixer::class, + DeclareStrictTypesFixer::class, + NoUnusedImportsFixer::class, + ]) + ->withPhpCsFixerSets(perCS20: true, symfonyRisky: true) +; diff --git a/src/Controller/MediaController.php b/src/Controller/MediaController.php index d668beb..1325d3c 100644 --- a/src/Controller/MediaController.php +++ b/src/Controller/MediaController.php @@ -12,9 +12,7 @@ class MediaController { - public function __construct(private MediaManager $mediaManager, private KernelInterface $kernel) - { - } + public function __construct(private MediaManager $mediaManager, private KernelInterface $kernel) {} public function uploadImage(Request $request): JsonResponse { diff --git a/src/Form/Type/FroalaEditorType.php b/src/Form/Type/FroalaEditorType.php index d2a930b..268e409 100644 --- a/src/Form/Type/FroalaEditorType.php +++ b/src/Form/Type/FroalaEditorType.php @@ -22,8 +22,7 @@ public function __construct( private ParameterBagInterface $parameterBag, private OptionManager $optionManager, private PluginProvider $pluginProvider, - ) { - } + ) {} public function buildForm(FormBuilderInterface $builder, array $options): void { @@ -82,7 +81,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $arrPlugin = $this->pluginProvider->obtainArrPluginToInclude($arrPluginEnabled, $arrPluginDisabled); - $view->vars['froala_arrOption']['pluginsEnabled'] = array_map(fn (string $plugin): string => 'trackChanges' === $plugin ? 'track_changes' : $plugin, $this->pluginProvider->obtainArrPluginCamelized($arrPlugin)); + $view->vars['froala_arrOption']['pluginsEnabled'] = array_map(fn(string $plugin): string => 'trackChanges' === $plugin ? 'track_changes' : $plugin, $this->pluginProvider->obtainArrPluginCamelized($arrPlugin)); $view->vars['froala_arrPluginJS'] = $this->pluginProvider->obtainArrPluginJS($arrPlugin); $view->vars['froala_arrPluginCSS'] = $this->pluginProvider->obtainArrPluginCSS($arrPlugin); $view->vars['froala_events'] = $arrEvent; diff --git a/src/LeaptFroalaEditorBundle.php b/src/LeaptFroalaEditorBundle.php index 1583ce2..7d0a375 100644 --- a/src/LeaptFroalaEditorBundle.php +++ b/src/LeaptFroalaEditorBundle.php @@ -6,6 +6,4 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -class LeaptFroalaEditorBundle extends Bundle -{ -} +class LeaptFroalaEditorBundle extends Bundle {} diff --git a/src/Service/OptionManager.php b/src/Service/OptionManager.php index 35eeaff..304e741 100644 --- a/src/Service/OptionManager.php +++ b/src/Service/OptionManager.php @@ -8,9 +8,7 @@ final class OptionManager { - public function __construct(private RouterInterface $router) - { - } + public function __construct(private RouterInterface $router) {} /** * Prepare options before building view. diff --git a/src/Twig/FroalaExtension.php b/src/Twig/FroalaExtension.php index a4f1d15..6262d99 100644 --- a/src/Twig/FroalaExtension.php +++ b/src/Twig/FroalaExtension.php @@ -12,9 +12,7 @@ final class FroalaExtension extends AbstractExtension { - public function __construct(private ParameterBagInterface $parameterBag, private Packages $packages) - { - } + public function __construct(private ParameterBagInterface $parameterBag, private Packages $packages) {} public function getFunctions(): array { diff --git a/src/Utility/UConfiguration.php b/src/Utility/UConfiguration.php index eb8457b..7af02cd 100644 --- a/src/Utility/UConfiguration.php +++ b/src/Utility/UConfiguration.php @@ -316,24 +316,33 @@ public static function getArrOptionAll(): array public static function getArrOption(): array { - return array_merge(array_merge( + return array_merge( array_merge( array_merge( - array_keys(self::OPTIONS_BOOLEAN), - array_keys(self::OPTIONS_INTEGER)), - array_keys(self::OPTIONS_STRING)), - array_keys(self::OPTIONS_ARRAY)), - array_keys(self::OPTIONS_OBJECT)); + array_merge( + array_keys(self::OPTIONS_BOOLEAN), + array_keys(self::OPTIONS_INTEGER), + ), + array_keys(self::OPTIONS_STRING), + ), + array_keys(self::OPTIONS_ARRAY), + ), + array_keys(self::OPTIONS_OBJECT), + ); } public static function getArrOptionCustom(): array { - return array_merge(array_merge( + return array_merge( array_merge( - array_keys(self::OPTIONS_BOOLEAN_CUSTOM), - array_keys(self::OPTIONS_STRING_CUSTOM)), - array_keys(self::OPTIONS_ARRAY_CUSTOM)), - array_keys(self::OPTIONS_OBJECT_CUSTOM)); + array_merge( + array_keys(self::OPTIONS_BOOLEAN_CUSTOM), + array_keys(self::OPTIONS_STRING_CUSTOM), + ), + array_keys(self::OPTIONS_ARRAY_CUSTOM), + ), + array_keys(self::OPTIONS_OBJECT_CUSTOM), + ); } public static function addArrOptionBoolean(NodeBuilder $nodeBuilder, bool $addDefaultValue = true): void diff --git a/tests/Form/Type/FroalaEditorTypeTest.php b/tests/Form/Type/FroalaEditorTypeTest.php index 33cb67f..f59260b 100644 --- a/tests/Form/Type/FroalaEditorTypeTest.php +++ b/tests/Form/Type/FroalaEditorTypeTest.php @@ -65,7 +65,7 @@ private function getForm(array $options = []): FormInterface $formType = new FroalaEditorType( $this->getParameterBag(), new OptionManager($router), - new PluginProvider() + new PluginProvider(), ); $factory = Forms::createFormFactoryBuilder() @@ -78,11 +78,15 @@ private function getForm(array $options = []): FormInterface private function getParameterBag(): ParameterBag { $array = array_merge( - UConfiguration::OPTIONS_STRING, UConfiguration::OPTIONS_STRING_CUSTOM, - UConfiguration::OPTIONS_BOOLEAN, UConfiguration::OPTIONS_BOOLEAN_CUSTOM, - UConfiguration::OPTIONS_ARRAY, UConfiguration::OPTIONS_ARRAY_CUSTOM, - UConfiguration::OPTIONS_OBJECT, UConfiguration::OPTIONS_OBJECT_CUSTOM, - UConfiguration::OPTIONS_INTEGER + UConfiguration::OPTIONS_STRING, + UConfiguration::OPTIONS_STRING_CUSTOM, + UConfiguration::OPTIONS_BOOLEAN, + UConfiguration::OPTIONS_BOOLEAN_CUSTOM, + UConfiguration::OPTIONS_ARRAY, + UConfiguration::OPTIONS_ARRAY_CUSTOM, + UConfiguration::OPTIONS_OBJECT, + UConfiguration::OPTIONS_OBJECT_CUSTOM, + UConfiguration::OPTIONS_INTEGER, ); $parameters = [];