Skip to content

Commit

Permalink
Add PHP Codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
navarr committed Jun 29, 2021
1 parent 7951edf commit 75997cb
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 12 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ jobs:
- name: Run PHPStan
run: vendor/bin/phpstan analyse src --level max

phpcs:
name: Code Style (PSR-12)
runs-on: ubuntu-latest
container:
image: davidalger/php:8.0
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Install Dependencies
run: composer2 install

- name: PHP Code Sniffer
run: vendor/bin/phpcs

infection:
name: Infection Check
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"roave/security-advisories": "dev-master",
"phpstan/phpstan": "^0.12.32",
"phpunit/phpunit": "^9.5",
"infection/infection": "^0.23.0"
"infection/infection": "^0.23.0",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<rule ref="PSR12"/>
<file>src</file>
</ruleset>
6 changes: 4 additions & 2 deletions src/Command/WhyBlockCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down Expand Up @@ -32,7 +33,8 @@ class WhyBlockCommand extends BaseCommand
private const LEGACY_ANNOTATION = 'include-legacy-annotations';
private const FAIL_ON_ERROR = 'fail-on-error';

#[Dependency('symfony/console', '^5', 'Command\'s setName, addArgument and addOption methods as well as InputArgument\'s constants of REQUIRED and VALUE_NONE',)]
// phpcs:ignore Generic.Files.LineLength.TooLong -- Attribute support pre PHP 8
#[Dependency('symfony/console', '^5', 'Command\'s setName, addArgument and addOption methods as well as InputArgument\'s constants of REQUIRED and VALUE_NONE')]
protected function configure(): void
{
$this->setName('why-block')
Expand Down Expand Up @@ -152,7 +154,7 @@ static function (DeclaredDependency $attribute) use ($packageToSearchFor, $versi
foreach ($failingAttributes as $failingAttribute) {
$output->writeln(
$failingAttribute->getReference() !== null
? str_replace(getcwd().'/', '', $failingAttribute->getReference())
? str_replace(getcwd() . '/', '', $failingAttribute->getReference())
: 'Unknown File'
. ': ' . $failingAttribute->getReason()
. ' (' . $failingAttribute->getVersion() . ')'
Expand Down
1 change: 1 addition & 0 deletions src/Data/DeclaredDependency.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down
17 changes: 10 additions & 7 deletions src/Model/AstParser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand All @@ -25,13 +26,15 @@ class AstParser implements ParserInterface

#[Dependency('nikic/php-parser', '^4')]
#[Dependency('navarr/attribute-dependency', '^1', 'Existence of Dependency attribute')]
public function parse(string $file): array
{
$astParser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
public function parse(
string $file
): array {
$astParser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$nameResolver = new NameResolver(null, ['replaceNodes' => true]);
$finder = new FindingVisitor(static function (Node $node) {
return $node instanceof Attribute
&& $node->name->toString() === Dependency::class;
$finder = new FindingVisitor(
static function (Node $node) {
return $node instanceof Attribute
&& $node->name->toString() === Dependency::class;
}
);

Expand Down Expand Up @@ -62,7 +65,7 @@ public function parse(string $file): array
$argIndex = [
0 => 'package',
1 => 'versionConstraint',
2 => 'reason'
2 => 'reason',
];

return array_map(
Expand Down
1 change: 1 addition & 0 deletions src/Model/FailOnIssueHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Model/IssueHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Model/LegacyParser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Model/NotifyOnIssueHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Model/ParserInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright 2021 Navarr Barnier. All Rights Reserved.
*/
Expand All @@ -21,8 +22,8 @@
* @dependency composer-plugin-api:^1|^2 Reliant Interfaces
* @dependency composer/composer:^1|^2 Existence of IOInterface and Composer class
*/
#[Dependency('composer-plugin-api','^1|^2','Reliant Interfaces')]
#[Dependency('composer/composer','^1|^2','Existence of IOInterface and Composer class')]
#[Dependency('composer-plugin-api', '^1|^2', 'Reliant Interfaces')]
#[Dependency('composer/composer', '^1|^2', 'Existence of IOInterface and Composer class')]
class Plugin implements PluginInterface, Capable, CommandProvider
{
public function activate(Composer $composer, IOInterface $io): void
Expand Down

0 comments on commit 75997cb

Please sign in to comment.