Skip to content

Commit

Permalink
Merge pull request #12 from worksome/feature/php-cs-fixer
Browse files Browse the repository at this point in the history
feat: add standardised docblock alignment
  • Loading branch information
owenvoke authored Apr 21, 2022
2 parents 42a7659 + 2619c19 commit 544ac79
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Worksomes Coding Style
This repository contains the coding style followed by Worksome.

It includes configuration for `phpcs`, `phpstan` and `rector`.
It includes configuration for `php-cs-fixer`, `phpcs`, `phpstan` and `rector`.

## Setup
Install this composer package
Expand All @@ -21,6 +21,8 @@ Add the following section to your `composer.json` file
```json
"scripts": {
"phpcs": "vendor/bin/phpcs",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --ansi",
"php-cs-fixer-ci": "vendor/bin/php-cs-fixer fix --dry-run --ansi",
"phpcbf": "vendor/bin/phpcbf",
"phpstan": "vendor/bin/phpstan analyse",
"rector-ci": "vendor/bin/rector process --dry-run --ansi",
Expand All @@ -33,6 +35,7 @@ Add the following section to your `composer.json` file
For using it simply run one of the scripts added to composer.
```
$ composer phpcs
$ composer php-cs-fixer
$ composer phpstan
$ composer rector-ci
```
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"nunomaduro/larastan": "^1.0 || ^2.0",
"rector/rector": "^0.12.0",
"jetbrains/phpstorm-attributes": "^1.0",
"phpstan/phpstan-mockery": "^1.0"
"phpstan/phpstan-mockery": "^1.0",
"friendsofphp/php-cs-fixer": "^3.8"
},
"require-dev": {
"composer/composer": "^2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("Worksome's Coding style has 3 stub files (phpcs, phpstan and rector)");

$files = [
'.php-cs-fixer.dist.php' => __DIR__ . '/../stubs/php-cs-fixer.dist.php.stub',
'phpcs.xml' => __DIR__ . '/../stubs/phpcs.xml.stub',
'phpstan.neon' => __DIR__ . '/../stubs/phpstan.neon.stub',
'rector.php' => __DIR__ . '/../stubs/rector.php.stub',
Expand All @@ -37,11 +38,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->getComposer()->getConfig()->merge([
'scripts' => [
"phpcs" => "vendor/bin/phpcs",
"php-cs-fixer" => "vendor/bin/php-cs-fixer fix --ansi",
"php-cs-fixer-ci" => "vendor/bin/php-cs-fixer fix --dry-run --ansi",
"phpcbf" => "vendor/bin/phpcbf",
"phpstan" => "vendor/bin/phpstan analyse",
"rector-ci" => "vendor/bin/rector process --dry-run --ansi",
"rector" => "vendor/bin/rector process --ansi",
]
]);

return 0;
}
}
43 changes: 43 additions & 0 deletions src/PhpCsFixerConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Worksome\CodingStyle;

use PhpCsFixer\Config;
use PhpCsFixer\ConfigInterface;

class PhpCsFixerConfig extends Config
{
const RULE_DEFINITIONS = [
'@worksome' => [
'phpdoc_align' => [
'align' => 'vertical',
],
'phpdoc_separation' => true,
],
'@worksome:risky' => [
// ...
],
];

public function __construct()
{
parent::__construct('Worksome');
}

public static function make(): self
{
return new self();
}

public function setRules(array $rules): ConfigInterface
{
foreach (array_keys(self::RULE_DEFINITIONS) as $key) {
if (($rules[$key] ?? false)) {
unset($rules[$key]);
$rules = array_merge(self::RULE_DEFINITIONS[$key], $rules);
}
}

return parent::setRules($rules);
}
}
21 changes: 21 additions & 0 deletions stubs/php-cs-fixer.dist.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use Worksome\CodingStyle\PhpCsFixerConfig;

require __DIR__.'/vendor/autoload.php';

$finder = Finder::create()
->in(__DIR__.'/app')
->in(__DIR__.'/tests')
->in(__DIR__.'/config');

return PhpCsFixerConfig::make()
->setFinder($finder)
->setRules([
'@worksome' => true,
'@worksome:risky' => true,
])
->setRiskyAllowed(true);

0 comments on commit 544ac79

Please sign in to comment.