Skip to content

Commit 75997cb

Browse files
committed
Add PHP Codesniffer
1 parent 7951edf commit 75997cb

12 files changed

+45
-12
lines changed

.github/workflows/commit.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ jobs:
3232
- name: Run PHPStan
3333
run: vendor/bin/phpstan analyse src --level max
3434

35+
phpcs:
36+
name: Code Style (PSR-12)
37+
runs-on: ubuntu-latest
38+
container:
39+
image: davidalger/php:8.0
40+
steps:
41+
- name: Checkout Repository
42+
uses: actions/checkout@v2
43+
44+
- name: Install Dependencies
45+
run: composer2 install
46+
47+
- name: PHP Code Sniffer
48+
run: vendor/bin/phpcs
49+
3550
infection:
3651
name: Infection Check
3752
runs-on: ubuntu-latest

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"roave/security-advisories": "dev-master",
1717
"phpstan/phpstan": "^0.12.32",
1818
"phpunit/phpunit": "^9.5",
19-
"infection/infection": "^0.23.0"
19+
"infection/infection": "^0.23.0",
20+
"squizlabs/php_codesniffer": "^3.6"
2021
},
2122
"autoload": {
2223
"psr-4": {

phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
<rule ref="PSR12"/>
4+
<file>src</file>
5+
</ruleset>

src/Command/WhyBlockCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/
@@ -32,7 +33,8 @@ class WhyBlockCommand extends BaseCommand
3233
private const LEGACY_ANNOTATION = 'include-legacy-annotations';
3334
private const FAIL_ON_ERROR = 'fail-on-error';
3435

35-
#[Dependency('symfony/console', '^5', 'Command\'s setName, addArgument and addOption methods as well as InputArgument\'s constants of REQUIRED and VALUE_NONE',)]
36+
// phpcs:ignore Generic.Files.LineLength.TooLong -- Attribute support pre PHP 8
37+
#[Dependency('symfony/console', '^5', 'Command\'s setName, addArgument and addOption methods as well as InputArgument\'s constants of REQUIRED and VALUE_NONE')]
3638
protected function configure(): void
3739
{
3840
$this->setName('why-block')
@@ -152,7 +154,7 @@ static function (DeclaredDependency $attribute) use ($packageToSearchFor, $versi
152154
foreach ($failingAttributes as $failingAttribute) {
153155
$output->writeln(
154156
$failingAttribute->getReference() !== null
155-
? str_replace(getcwd().'/', '', $failingAttribute->getReference())
157+
? str_replace(getcwd() . '/', '', $failingAttribute->getReference())
156158
: 'Unknown File'
157159
. ': ' . $failingAttribute->getReason()
158160
. ' (' . $failingAttribute->getVersion() . ')'

src/Data/DeclaredDependency.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/

src/Model/AstParser.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/
@@ -25,13 +26,15 @@ class AstParser implements ParserInterface
2526

2627
#[Dependency('nikic/php-parser', '^4')]
2728
#[Dependency('navarr/attribute-dependency', '^1', 'Existence of Dependency attribute')]
28-
public function parse(string $file): array
29-
{
30-
$astParser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
29+
public function parse(
30+
string $file
31+
): array {
32+
$astParser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
3133
$nameResolver = new NameResolver(null, ['replaceNodes' => true]);
32-
$finder = new FindingVisitor(static function (Node $node) {
33-
return $node instanceof Attribute
34-
&& $node->name->toString() === Dependency::class;
34+
$finder = new FindingVisitor(
35+
static function (Node $node) {
36+
return $node instanceof Attribute
37+
&& $node->name->toString() === Dependency::class;
3538
}
3639
);
3740

@@ -62,7 +65,7 @@ public function parse(string $file): array
6265
$argIndex = [
6366
0 => 'package',
6467
1 => 'versionConstraint',
65-
2 => 'reason'
68+
2 => 'reason',
6669
];
6770

6871
return array_map(

src/Model/FailOnIssueHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/

src/Model/IssueHandlerInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/

src/Model/LegacyParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/

src/Model/NotifyOnIssueHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/

src/Model/ParserInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/

src/Plugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @copyright 2021 Navarr Barnier. All Rights Reserved.
45
*/
@@ -21,8 +22,8 @@
2122
* @dependency composer-plugin-api:^1|^2 Reliant Interfaces
2223
* @dependency composer/composer:^1|^2 Existence of IOInterface and Composer class
2324
*/
24-
#[Dependency('composer-plugin-api','^1|^2','Reliant Interfaces')]
25-
#[Dependency('composer/composer','^1|^2','Existence of IOInterface and Composer class')]
25+
#[Dependency('composer-plugin-api', '^1|^2', 'Reliant Interfaces')]
26+
#[Dependency('composer/composer', '^1|^2', 'Existence of IOInterface and Composer class')]
2627
class Plugin implements PluginInterface, Capable, CommandProvider
2728
{
2829
public function activate(Composer $composer, IOInterface $io): void

0 commit comments

Comments
 (0)