Skip to content

Commit

Permalink
Setup symplify/easy-coding-standard (#1305)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Jul 19, 2023
2 parents b1be135 + c19f178 commit e8217a3
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 81 deletions.
4 changes: 1 addition & 3 deletions .gitattributes
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -3,7 +3,6 @@
*~
.cache/
.idea/*
.php_cs.cache
.phpdoc/
.phpunit.result.cache
build/
Expand Down
31 changes: 0 additions & 31 deletions .php-cs-fixer.dist.php

This file was deleted.

30 changes: 0 additions & 30 deletions .php_cs

This file was deleted.

15 changes: 0 additions & 15 deletions .styleci.yml

This file was deleted.

8 changes: 8 additions & 0 deletions composer.json
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": [
Expand Down
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions ecs.php
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\Casing\ConstantCaseFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
use PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer;
use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer;
use PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->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
]);
};

0 comments on commit e8217a3

Please sign in to comment.