diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 000000000..3bbdc6106 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,32 @@ +name: php-cs-fixer + +permissions: + contents: read + +on: + pull_request: &ignore-paths + paths-ignore: + - 'docs/**' + - '.github/CONTRIBUTING.md' + - '.github/FUNDING.yml' + - '.github/SECURITY.md' + - 'README.md' + - 'CHANGELOG.md' + - 'LICENSE.md' + - 'UPGRADE.md' + - '.gitignore' + - '.gitattributes' + - '.editorconfig' + - 'docker-compose.yml' + - 'Dockerfile' + - 'Makefile' + - 'phpunit.xml.dist' + + push: *ignore-paths + +jobs: + php-cs-fixer: + uses: yiisoft/yii2-actions/.github/workflows/php-cs-fixer.yml@9bfbe47bd91bc31a6ff9f0ea77ba3724d7816c3d # master + with: + configuration: .php-cs-fixer.dist.php + php-version: '["8.3"]' diff --git a/.github/workflows/linter.yml b/.github/workflows/phpcs.yml similarity index 97% rename from .github/workflows/linter.yml rename to .github/workflows/phpcs.yml index ae398fc2d..504e5b84e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/phpcs.yml @@ -1,4 +1,4 @@ -name: linter +name: phpcs permissions: contents: read diff --git a/.gitignore b/.gitignore index 3431d51a8..a6b32142b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,7 @@ composer.lock coverage.xml runtime + +# PHP CS Fixer +.php-cs-fixer.php +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 000000000..90f0b61d2 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,31 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->notPath([ + '#(^|/)views/#', + '#(^|/)config/#', + '#(^|/)docker/#', + ]); + +return (new Config()) + ->setFinder($finder) + ->setRules([ + 'no_unused_imports' => true, + 'phpdoc_scalar' => true, + 'header_comment' => [ + 'comment_type' => 'PHPDoc', + 'header' => $header, + 'location' => 'after_open', + ], + ]); diff --git a/composer.json b/composer.json index ed12c53bb..05081fa39 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,9 @@ "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", "rector/rector": "^2.6", - "mspirkov/yii2-rector": "^0.1" + "mspirkov/yii2-rector": "^0.1", + "slevomat/coding-standard": "^8.31", + "friendsofphp/php-cs-fixer": "^3.95" }, "suggest": { "ext-pcntl": "Need for process signals.", @@ -71,7 +73,8 @@ "config": { "allow-plugins": { "yiisoft/yii2-composer": true, - "php-http/discovery": true + "php-http/discovery": true, + "dealerdirect/phpcodesniffer-composer-installer": true } }, "extra": { @@ -86,8 +89,8 @@ } ], "scripts": { - "cs": "./vendor/bin/phpcs", - "cs-fix": "./vendor/bin/phpcbf", + "cs": "./vendor/bin/phpcs && ./vendor/bin/php-cs-fixer check", + "cs-fix": "./vendor/bin/phpcbf && ./vendor/bin/php-cs-fixer fix", "static": "./vendor/bin/phpstan --memory-limit=-1", "tests": "./make test", "rector": "./vendor/bin/rector" diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e9eca6400..318c731b6 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -2,6 +2,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ae437f2f7..d0c52da59 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -678,6 +678,12 @@ parameters: count: 1 path: src/drivers/sqs/Queue.php + - + message: '#^Parameter \#1 \$args of method Aws\\Sqs\\SqsClient\:\:receiveMessage\(\) expects array\{QueueUrl\?\: string, AttributeNames\?\: list\<''All''\|''ApproximateNumberOf…''\|''ContentBasedDedupli…''\|''CreatedTimestamp''\|''DeduplicationScope''\|''DelaySeconds''\|''FifoQueue''\|''FifoThroughputLimit''\|''KmsDataKeyReusePeri…''\|''KmsMasterKeyId''\|''LastModifiedTimesta…''\|''MaximumMessageSize''\|''MessageRetentionPer…''\|''Policy''\|''QueueArn''\|''ReceiveMessageWaitT…''\|''RedriveAllowPolicy''\|''RedrivePolicy''\|''SqsManagedSseEnabled''\|''VisibilityTimeout''\>, MessageSystemAttributeNames\?\: list\<''All''\|''ApproximateFirstRec…''\|''ApproximateReceiveC…''\|''AWSTraceHeader''\|''DeadLetterQueueSour…''\|''MessageDeduplicatio…''\|''MessageGroupId''\|''SenderId''\|''SentTimestamp''\|''SequenceNumber''\>, MessageAttributeNames\?\: list\, MaxNumberOfMessages\?\: int, VisibilityTimeout\?\: int, WaitTimeSeconds\?\: int, ReceiveRequestAttemptId\?\: string, \.\.\.\}, array\{QueueUrl\: string, AttributeNames\: array\{''ApproximateReceiveC…''\}, MessageAttributeNames\: array\{''TTR''\}, MaxNumberOfMessages\: 1, VisibilityTimeout\: int, WaitTimeSeconds\: int\} given\.$#' + identifier: argument.type + count: 1 + path: src/drivers/sqs/Queue.php + - message: '#^Property yii\\queue\\sqs\\Queue\:\:\$serializer type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -1337,9 +1343,3 @@ parameters: identifier: missingType.iterableValue count: 1 path: tests/serializers/TestCase.php - - - - message: '#^Access to constant ATTR_INIT_COMMAND on an unknown class Pdo\\Mysql\.$#' - identifier: class.notFound - count: 1 - path: tests/app/config/main.php diff --git a/src/cli/InfoAction.php b/src/cli/InfoAction.php index d13e99c97..42c28902e 100644 --- a/src/cli/InfoAction.php +++ b/src/cli/InfoAction.php @@ -11,7 +11,6 @@ namespace yii\queue\cli; use yii\base\NotSupportedException; -use yii\console\Controller; use yii\helpers\Console; use yii\queue\interfaces\DelayedCountInterface; use yii\queue\interfaces\DoneCountInterface; diff --git a/tests/cli/Queue.php b/tests/cli/Queue.php index d8a4e028f..846bd715e 100644 --- a/tests/cli/Queue.php +++ b/tests/cli/Queue.php @@ -32,6 +32,7 @@ public function status($id): int { throw new NotSupportedException('"status" method is not supported.'); } + /** * @inheritdoc */ diff --git a/tests/drivers/db/TestCase.php b/tests/drivers/db/TestCase.php index de4741791..d69cb5c8c 100644 --- a/tests/drivers/db/TestCase.php +++ b/tests/drivers/db/TestCase.php @@ -13,7 +13,6 @@ use tests\app\PriorityJob; use tests\app\RetryJob; use tests\drivers\CliTestCase; -use Yii; use yii\db\Query; /**