Skip to content

Commit

Permalink
Use php-cs-fixer as coding style tool
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Jun 4, 2021
1 parent a5fc431 commit 5f56351
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ utils/ export-ignore
rector.php export-ignore
phpunit.xml.dist export-ignore
phpstan.neon.dist export-ignore
.php-cs-fixer.dist.php export-ignore

# The source user guide, either
user_guide_src/ export-ignore
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
- name: Install dependencies
run: |
composer update --ansi --no-interaction
composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan codeigniter4/codeigniter4-standard squizlabs/php_codesniffer
composer remove --ansi --dev --unused -W rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config
php -r 'file_put_contents("vendor/laminas/laminas-zendframework-bridge/src/autoload.php", "");'
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
Expand All @@ -140,7 +140,7 @@ jobs:
- if: github.repository_owner == 'codeigniter4' && matrix.php-versions == '7.4'
name: Run Coveralls
run: |
composer global require php-coveralls/php-coveralls:^2.4
composer global require --ansi php-coveralls/php-coveralls:^2.4
php-coveralls --coverage_clover=build/logs/clover.xml -v
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ nb-configuration.xml
/results/
/phpunit*.xml
/.phpunit.*.cache

/.php-cs-fixer.php
34 changes: 34 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use Nexus\CsConfig\Factory;
use PhpCsFixer\Finder;
use Utils\PhpCsFixer\CodeIgniter4;

$finder = Finder::create()
->files()
->in([
__DIR__ . '/app', // @todo relocate when `header_comment` is enabled
__DIR__ . '/public', // @todo relocate when `header_comment` is enabled
__DIR__ . '/system',
__DIR__ . '/tests',
__DIR__ . '/utils',
])
->exclude(['ThirdParty'])
->notName('#Foobar.php$#')
->append([
__FILE__,
__DIR__ . '/rector.php',
__DIR__ . '/spark',
]);

$overrides = [];

$options = [
'cacheFile' => 'build/.php-cs-fixer.cache',
'finder' => $finder,
];

// @todo change to `forLibrary()` when `header_comment` is enabled
return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();
6 changes: 3 additions & 3 deletions admin/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"psr/log": "^1.1"
},
"require-dev": {
"codeigniter4/codeigniter4-standard": "^1.0",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.0",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.1",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1",
"squizlabs/php_codesniffer": "^3.3"
"predis/predis": "^1.1"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"psr/log": "^1.1"
},
"require-dev": {
"codeigniter4/codeigniter4-standard": "^1.0",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.0",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.1",
"nexusphp/tachycardia": "^1.0",
"phpstan/phpstan": "0.12.88",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1",
"rector/rector": "0.11.8",
"squizlabs/php_codesniffer": "^3.3",
"symplify/package-builder": "^9.3"
},
"suggest": {
Expand Down
26 changes: 26 additions & 0 deletions utils/PhpCsFixer/CodeIgniter4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Utils\PhpCsFixer;

use Nexus\CsConfig\Ruleset\AbstractRuleset;

/**
* Defines the ruleset used for the CodeIgniter4 organization.
*
* @internal
*/
final class CodeIgniter4 extends AbstractRuleset
{
public function __construct()
{
$this->name = 'CodeIgniter4 Revised Coding Standards';

$this->rules = [];

$this->requiredPHPVersion = 70300;

$this->autoActivateIsRiskyAllowed = true;
}
}

0 comments on commit 5f56351

Please sign in to comment.