Skip to content

Commit

Permalink
Configure rules for PHP 7.4, 8.0 and 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Aug 25, 2022
1 parent c817f0c commit f006cb0
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 205 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/phpstan.neon.dist export-ignore
/.php-cs-fixer.dist.php export-ignore
71 changes: 0 additions & 71 deletions .github/workflows/tests.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/vendor/

/.php-cs-fixer.cache
/.phpunit.result.cache

/composer.lock
/phpstan.neon
/phpunit.xml
15 changes: 15 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Beste\PhpCsFixer\Config;
use Ergebnis\PhpCsFixer\Config\Factory;

$config = Factory::fromRuleSet(new Config\RuleSet\Php81());

$config
->getFinder()
->in(__DIR__)
->ignoreDotFiles(false);

return $config;
11 changes: 0 additions & 11 deletions .php-cs-fixer.php

This file was deleted.

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# CHANGELOG

## [Unreleased]

## [1.0.0] - 2022-08-25

* Rules extend the Ergebnis rules with the following modifications:
* `blank_line_between_import_groups`: Blank lines are put between import groups
* `global_namespace_import`: classes and functions are imported
* `phpdoc_align`: PHPDoc items are left-aligned
* `phpdoc_types_order`: types are not sorted, `null` is always last
* `php_unit_test_class_requires_covers`: Tests don't require `@covers` annotations
* `yoda_style`: Condition styles are not enforced

[Unreleased]: https://github.com/beste/php-cs-fixer-config/compare/1.0.0...main
[1.0.0]: https://github.com/beste/php-cs-fixer-config/tree/1.0.0
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# PHP CS Fixer Config
# BESTE PHP CS Fixer Config

PHP CS Fixer Config used in BESTE projects
PHP CS Fixer Config used in BESTE projects, based on
[`ergebnis/php-cs-fixer-config`](https://github.com/ergebnis/php-cs-fixer-config).

## Installation

```shell
composer require beste/php-cs-fixer-config
composer require --dev beste/php-cs-fixer-config
```

## Running tests
## Usage

```shell
composer run tests
```
Detailed usage instructions can be found in the
[README of `ergebnis/php-cs-fixer-config`](https://github.com/ergebnis/php-cs-fixer-config/blob/main/README.md).

### Available configurations

* [`Beste\PhpCsFixer\Config\RuleSet\Php74`](src/Config/RuleSet/Php74.php)
* [`Beste\PhpCsFixer\Config\RuleSet\Php80`](src/Config/RuleSet/Php80.php)
* [`Beste\PhpCsFixer\Config\RuleSet\Php81`](src/Config/RuleSet/Php81.php)

## Changelog

Please have a look at [`CHANGELOG.md`](CHANGELOG.md).

## Credits

This project extends [`ergebnis/php-cs-fixer-config`](https://github.com/ergebnis/php-cs-fixer-config).
41 changes: 3 additions & 38 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,15 @@
}
],
"require": {
"php": "~8.0.0 || ~8.1.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.28",
"ergebnis/php-cs-fixer-config": "^4.4",
"ergebnis/phpstan-rules": "^1.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpstan/phpstan-strict-rules": "^1.3.0",
"phpunit/phpunit": "^9.5"
"php": "^8.1",
"ergebnis/php-cs-fixer-config": "^4.7"
},
"autoload": {
"psr-4": {
"Beste\\PhpCsFixer\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Beste\\PhpCsFixer\\Tests\\": "tests"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"composer/package-versions-deprecated": true,
"ergebnis/composer-normalize": true
},
"sort-packages": true
},
"scripts": {
"cs": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose",
"phpstan": "vendor/bin/phpstan analyse",
"phpunit": "vendor/bin/phpunit",
"test": [
"@phpstan",
"@phpunit"
]
},
"scripts-descriptions": {
"cs": "Applies coding standards",
"phpstan": "Runs static analysis with PHPStan",
"phpunit": "Runs tests with PHPUnit",
"test": "Runs static analysis and test suites"
"cs": "vendor/bin/php-cs-fixer fix --diff --verbose"
}
}
6 changes: 0 additions & 6 deletions phpstan.neon.dist

This file was deleted.

19 changes: 0 additions & 19 deletions phpunit.xml.dist

This file was deleted.

36 changes: 36 additions & 0 deletions src/Config/RuleSet/Php74.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Beste\PhpCsFixer\Config\RuleSet;

use Ergebnis\PhpCsFixer\Config\RuleSet;
use Ergebnis\PhpCsFixer\Config\RuleSet\Php74 as ErgebnisPhp74;

use function array_merge;

final class Php74 implements RuleSet
{
use RuleOverrides;
private ErgebnisPhp74 $base;

public function __construct(private readonly ?string $header = null)
{
$this->base = new ErgebnisPhp74($this->header);
}

public function name(): string
{
return 'BESTE (PHP 7.4)';
}

public function targetPhpVersion(): int
{
return $this->base->targetPhpVersion();
}

public function rules(): array
{
return array_merge($this->base->rules(), $this->ruleOverrides());
}
}
36 changes: 36 additions & 0 deletions src/Config/RuleSet/Php80.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Beste\PhpCsFixer\Config\RuleSet;

use Ergebnis\PhpCsFixer\Config\RuleSet;
use Ergebnis\PhpCsFixer\Config\RuleSet\Php80 as ErgebnisPhp80;

use function array_merge;

final class Php80 implements RuleSet
{
use RuleOverrides;
private ErgebnisPhp80 $base;

public function __construct(private readonly ?string $header = null)
{
$this->base = new ErgebnisPhp80($this->header);
}

public function name(): string
{
return 'BESTE (PHP 8.0)';
}

public function targetPhpVersion(): int
{
return $this->base->targetPhpVersion();
}

public function rules(): array
{
return array_merge($this->base->rules(), $this->ruleOverrides());
}
}
36 changes: 36 additions & 0 deletions src/Config/RuleSet/Php81.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Beste\PhpCsFixer\Config\RuleSet;

use Ergebnis\PhpCsFixer\Config\RuleSet;
use Ergebnis\PhpCsFixer\Config\RuleSet\Php81 as ErgebnisPhp81;

use function array_merge;

final class Php81 implements RuleSet
{
use RuleOverrides;
private ErgebnisPhp81 $base;

public function __construct(private readonly ?string $header = null)
{
$this->base = new ErgebnisPhp81($this->header);
}

public function name(): string
{
return 'BESTE (PHP 8.1)';
}

public function targetPhpVersion(): int
{
return $this->base->targetPhpVersion();
}

public function rules(): array
{
return array_merge($this->base->rules(), $this->ruleOverrides());
}
}
29 changes: 29 additions & 0 deletions src/Config/RuleSet/RuleOverrides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Beste\PhpCsFixer\Config\RuleSet;

trait RuleOverrides
{
protected function ruleOverrides(): array
{
return [
'blank_line_between_import_groups' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => true,
],
'phpdoc_align' => [
'align' => 'left',
],
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
],
'php_unit_test_class_requires_covers' => false,
'yoda_style' => false,
];
}
}
Loading

0 comments on commit f006cb0

Please sign in to comment.