diff --git a/.gitattributes b/.gitattributes index f2b9d821f..b31648320 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,10 +6,8 @@ .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.php_cs export-ignore -.php-cs-fixer.dist.php export-ignore -.styleci.yml export-ignore codecov.yml export-ignore +ecs.php export-ignore Makefile export-ignore phpunit.xml.dist export-ignore psalm-baseline.xml export-ignore diff --git a/.gitignore b/.gitignore index 10e870830..8d617c438 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ *~ .cache/ .idea/* -.php_cs.cache .phpdoc/ .phpunit.result.cache build/ diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 5bb408553..000000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,31 +0,0 @@ -in([ - 'src', - 'tests', - ]); - - - return (new PhpCsFixer\Config()) - ->setRules(array( - '@PSR2' => true, - )) - ->setUsingCache(true) - ->setFinder($finder) - ; -} - -$finder = DefaultFinder::create()->in( - [ - 'src', - 'tests', - ]); - -return Config::create() - ->level('psr2') - ->setUsingCache(true) - ->finder($finder); diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 6f47e78fc..000000000 --- a/.php_cs +++ /dev/null @@ -1,30 +0,0 @@ -in([ - 'src', - 'tests', - ]); - - return PhpCsFixer\Config::create() - ->setRules(array( - '@PSR2' => true, - )) - ->setUsingCache(true) - ->setFinder($finder) - ; -} - -$finder = DefaultFinder::create()->in( - [ - 'src', - 'tests', - ]); - -return Config::create() - ->level('psr2') - ->setUsingCache(true) - ->finder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 614c1fbf7..000000000 --- a/.styleci.yml +++ /dev/null @@ -1,15 +0,0 @@ -preset: psr12 - -version: 8.1 - -enabled: - - symfony_braces - -disabled: - - const_visibility_required - - psr12_braces - -finder: - not-name: - - Php80LanguageFeaturesTest.php - - SemiReservedWordsAsMethods.php diff --git a/composer.json b/composer.json index 5870ef66f..f3392c13b 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ "require-dev": { "phpunit/phpunit": "^8.5 || ^9.3", "psalm/plugin-phpunit": "^0.18.4", + "symplify/easy-coding-standard": "^11.5.0", "vimeo/psalm": "^5.13.1" }, "conflict": { @@ -85,9 +86,16 @@ "scripts": { "check": [ "@composer validate", + "@ecs", "@test" ], "docs": "vendor/bin/phpdoc -d src -t docs/api", + "ecs": [ + "@ecs:fix", + "@ecs:check" + ], + "ecs:check": "ecs check --clear-cache || true", + "ecs:fix": "ecs check --clear-cache --fix", "phpunit": "vendor/bin/phpunit --colors=always --testdox --stop-on-failure", "phpunit:coverage": "vendor/bin/phpunit --colors=always --testdox --stop-on-failure --coverage-clover=coverage.xml", "psalm": [ diff --git a/composer.lock b/composer.lock index a6f6846f7..69d4e6cc6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9a7169df963fb59b6567a57193b109c2", + "content-hash": "7bd77f1dc711b159671cf644501c6594", "packages": [ { "name": "hamcrest/hamcrest-php", @@ -3822,6 +3822,64 @@ ], "time": "2023-03-14T06:11:53+00:00" }, + { + "name": "symplify/easy-coding-standard", + "version": "11.5.0", + "source": { + "type": "git", + "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", + "reference": "1d2400f7bfe92e3754ce71f0782f2c0521bade3d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/1d2400f7bfe92e3754ce71f0782f2c0521bade3d", + "reference": "1d2400f7bfe92e3754ce71f0782f2c0521bade3d", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "friendsofphp/php-cs-fixer": "<3.0", + "squizlabs/php_codesniffer": "<3.6", + "symplify/coding-standard": "<11.3" + }, + "bin": [ + "bin/ecs" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer", + "keywords": [ + "Code style", + "automation", + "fixer", + "static analysis" + ], + "support": { + "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/11.5.0" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2023-06-21T06:26:15+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", diff --git a/ecs.php b/ecs.php new file mode 100644 index 000000000..5db8bf640 --- /dev/null +++ b/ecs.php @@ -0,0 +1,82 @@ +parallel(); + + $ecsConfig->sets([ + SetList::ARRAY, + SetList::CLEAN_CODE, + SetList::COMMON, + SetList::CONTROL_STRUCTURES, + SetList::NAMESPACES, + SetList::PSR_12, + SetList::DOCBLOCK, + SetList::PHPUNIT, + SetList::SPACES, + SetList::STRICT, + ]); + + $ecsConfig->rules([ + NoEmptyStatementFixer::class, + ]); + + $ecsConfig->ruleWithConfiguration(GlobalNamespaceImportFixer::class, [ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ]); + + $ecsConfig->ruleWithConfiguration(OrderedImportsFixer::class, [ + 'imports_order' => ['class', 'const', 'function'], + ]); + + $ecsConfig->ruleWithConfiguration(PhpdocAlignFixer::class, [ + 'tags' => ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], + ]); + + $ecsConfig->ruleWithConfiguration(PhpUnitTestCaseStaticMethodCallsFixer::class, [ + 'call_type' => 'self', + ]); + + $ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [ + 'syntax' => 'short', + ]); + + $ecsConfig->ruleWithConfiguration(ConstantCaseFixer::class, [ + 'case' => 'lower', + ]); + + $ecsConfig->ruleWithConfiguration(OrderedClassElementsFixer::class, [ + 'sort_algorithm' => 'alpha', + ]); + + $ecsConfig->ruleWithConfiguration(OrderedInterfacesFixer::class, [ + 'order' => 'alpha', + ]); + + $ecsConfig->paths([ + __FILE__, + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $ecsConfig->skip([ + __DIR__ . '/src/Mockery/Mock.php', + __DIR__ . '/tests/Fixture/*', + __DIR__ . '/tests/Mockery/*', // skip temporarily, it still has legacy code + ]); +};