Skip to content

Commit 703d5ef

Browse files
committed
First working version
1 parent 0a62a0f commit 703d5ef

File tree

8 files changed

+84
-271
lines changed

8 files changed

+84
-271
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/.github/ export-ignore
2-
/test/ export-ignore
32
/.editorconfig export-ignore
43
/.gitattributes export-ignore
54
/.gitignore export-ignore
6-
/.php-cs-fixer.php export-ignore

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/.build/
2-
/.notes/
1+
/composer.lock
32
/vendor/
3+
.php-cs-fixer.cache
4+
.php-cs-fixer.laravel.cache

.php-cs-fixer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use SzepeViktor\PhpCsFixer\Laravel\Factory;
4+
5+
$config = Factory::fromLaravelRuleSet();
6+
7+
$config->getFinder()
8+
->in([
9+
__DIR__ . '/src',
10+
])
11+
;
12+
13+
return $config;

README.md

Lines changed: 12 additions & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -1,261 +1,33 @@
11
# php-cs-fixer-config
22

3-
[![Integrate](https://github.com/ergebnis/php-cs-fixer-config/workflows/Integrate/badge.svg)](https://github.com/ergebnis/php-cs-fixer-config/actions)
4-
[![Prune](https://github.com/ergebnis/php-cs-fixer-config/workflows/Prune/badge.svg)](https://github.com/ergebnis/php-cs-fixer-config/actions)
5-
[![Release](https://github.com/ergebnis/php-cs-fixer-config/workflows/Release/badge.svg)](https://github.com/ergebnis/php-cs-fixer-config/actions)
6-
[![Renew](https://github.com/ergebnis/php-cs-fixer-config/workflows/Renew/badge.svg)](https://github.com/ergebnis/php-cs-fixer-config/actions)
7-
8-
[![Code Coverage](https://codecov.io/gh/ergebnis/php-cs-fixer-config/branch/main/graph/badge.svg)](https://codecov.io/gh/ergebnis/php-cs-fixer-config)
9-
[![Type Coverage](https://shepherd.dev/github/ergebnis/php-cs-fixer-config/coverage.svg)](https://shepherd.dev/github/ergebnis/php-cs-fixer-config)
10-
11-
[![Latest Stable Version](https://poser.pugx.org/ergebnis/php-cs-fixer-config/v/stable)](https://packagist.org/packages/ergebnis/php-cs-fixer-config)
12-
[![Total Downloads](https://poser.pugx.org/ergebnis/php-cs-fixer-config/downloads)](https://packagist.org/packages/ergebnis/php-cs-fixer-config)
13-
14-
Provides a configuration factory and multiple rule sets for [`friendsofphp/php-cs-fixer`](http://github.com/FriendsOfPHP/PHP-CS-Fixer).
15-
163
## Installation
174

185
Run
196

207
```sh
21-
$ composer require --dev ergebnis/php-cs-fixer-config
8+
composer require --dev szepeviktor/php-cs-fixer-laravel-ruleset
229
```
2310

2411
## Usage
2512

2613
### Configuration
2714

28-
Pick one of the rule sets:
29-
30-
- [`Ergebnis\PhpCsFixer\RuleSet\Php74`](src/RuleSet/Php74.php)
31-
- [`Ergebnis\PhpCsFixer\RuleSet\Php80`](src/RuleSet/Php80.php)
32-
- [`Ergebnis\PhpCsFixer\RuleSet\Php81`](src/RuleSet/Php81.php)
33-
3415
Create a configuration file `.php-cs-fixer.php` in the root of your project:
3516

3617
```php
37-
<?php
38-
39-
use Ergebnis\PhpCsFixer\Config;
18+
use SzepeViktor\PhpCsFixer\Laravel\Factory;
4019

41-
$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74());
20+
$config = Factory::fromLaravelRuleSet();
4221

43-
$config->getFinder()->in(__DIR__);
44-
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
22+
$config->getFinder()
23+
->in([
24+
__DIR__ . '/app',
25+
__DIR__ . '/config',
26+
__DIR__ . '/database',
27+
__DIR__ . '/routes',
28+
__DIR__ . '/tests',
29+
])
30+
;
4531

4632
return $config;
4733
```
48-
49-
### Git
50-
51-
All configuration examples use the caching feature, and if you want to use it as well, you should add the cache directory to `.gitignore`:
52-
53-
```diff
54-
+ /.build/
55-
/vendor/
56-
```
57-
58-
:bulb: Personally, I prefer to use a `.build` directory for storing build artifacts.
59-
60-
### Configuration with header
61-
62-
:bulb: Optionally specify a header:
63-
64-
```diff
65-
<?php
66-
67-
use Ergebnis\PhpCsFixer\Config;
68-
69-
+$header = <<<EOF
70-
+Copyright (c) 2020 Andreas Möller
71-
+
72-
+For the full copyright and license information, please view
73-
+the LICENSE file that was distributed with this source code.
74-
+
75-
+@see https://github.com/ergebnis/php-cs-fixer-config
76-
+EOF;
77-
78-
-$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74());
79-
+$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74($header));
80-
81-
$config->getFinder()->in(__DIR__);
82-
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
83-
84-
return $config;
85-
```
86-
87-
This will enable and configure the [`HeaderCommentFixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.1.1/src/Fixer/Comment/HeaderCommentFixer.php), so that
88-
file headers will be added to PHP files, for example:
89-
90-
```php
91-
<?php
92-
93-
/**
94-
* Copyright (c) 2020 Andreas Möller
95-
*
96-
* For the full copyright and license information, please view
97-
* the LICENSE file that was distributed with this source code.
98-
*
99-
* @see https://github.com/ergebnis/php-cs-fixer-config
100-
*/
101-
```
102-
103-
### Configuration with override rules
104-
105-
:bulb: Optionally override rules from a rule set by passing in an array of rules to be merged in:
106-
107-
```diff
108-
<?php
109-
110-
use Ergebnis\PhpCsFixer\Config;
111-
112-
-$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74());
113-
+$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74(), [
114-
+ 'mb_str_functions' => false,
115-
+ 'strict_comparison' => false,
116-
+]);
117-
118-
$config->getFinder()->in(__DIR__);
119-
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');
120-
121-
return $config;
122-
```
123-
124-
### Makefile
125-
126-
If you like [`Makefile`](https://www.gnu.org/software/make/manual/make.html#Introduction)s, create a `Makefile` with a `coding-standards` target:
127-
128-
```diff
129-
+.PHONY: coding-standards
130-
+coding-standards: vendor
131-
+ mkdir -p .build/php-cs-fixer
132-
+ vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose
133-
134-
vendor: composer.json composer.lock
135-
composer validate
136-
composer install
137-
```
138-
139-
Run
140-
141-
```
142-
$ make coding-standards
143-
```
144-
145-
to automatically fix coding standard violations.
146-
147-
### Composer script
148-
149-
If you like [`composer` scripts](https://getcomposer.org/doc/articles/scripts.md), add a `coding-standards` script to `composer.json`:
150-
151-
```diff
152-
{
153-
"name": "foo/bar",
154-
"require": {
155-
"php": "^7.3",
156-
},
157-
"require-dev": {
158-
"ergebnis/php-cs-fixer-config": "~1.0.0"
159-
+ },
160-
+ "scripts": {
161-
+ "coding-standards": [
162-
+ "mkdir -p .build/php-cs-fixer",
163-
+ "php-cs-fixer fix --diff --verbose"
164-
+ ]
165-
}
166-
}
167-
```
168-
169-
Run
170-
171-
```
172-
$ composer coding-standards
173-
```
174-
175-
to automatically fix coding standard violations.
176-
177-
### GitHub Actions
178-
179-
If you like [GitHub Actions](https://github.com/features/actions), add a `coding-standards` job to your workflow:
180-
181-
```diff
182-
on:
183-
pull_request: null
184-
push:
185-
branches:
186-
- main
187-
188-
name: "Integrate"
189-
190-
jobs:
191-
+ coding-standards:
192-
+ name: "Coding Standards"
193-
+
194-
+ runs-on: ubuntu-latest
195-
+
196-
+ strategy:
197-
+ matrix:
198-
+ php-version:
199-
+ - "7.3"
200-
+
201-
+ steps:
202-
+ - name: "Checkout"
203-
+ uses: "actions/checkout@v2"
204-
+
205-
+ - name: "Install PHP with extensions"
206-
+ uses: "shivammathur/setup-php@v2"
207-
+ with:
208-
+ coverage: "none"
209-
+ php-version: "${{ matrix.php-version }}"
210-
+
211-
+ - name: "Cache dependencies installed with composer"
212-
+ uses: "actions/cache@v2"
213-
+ with:
214-
+ path: "~/.composer/cache"
215-
+ key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
216-
+ restore-keys: "php-${{ matrix.php-version }}-composer-"
217-
+
218-
+ - name: "Install locked dependencies with composer"
219-
+ run: "composer install --no-interaction --no-progress --no-suggest"
220-
+
221-
+ - name: "Create cache directory for friendsofphp/php-cs-fixer"
222-
+ run: mkdir -p .build/php-cs-fixer
223-
+
224-
+ - name: "Cache cache directory for friendsofphp/php-cs-fixer"
225-
+ uses: "actions/cache@v2"
226-
+ with:
227-
+ path: "~/.build/php-cs-fixer"
228-
+ key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.sha }}"
229-
+ restore-keys: "php-${{ matrix.php-version }}-php-cs-fixer-"
230-
+
231-
+ - name: "Run friendsofphp/php-cs-fixer"
232-
+ run: "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run --verbose"
233-
```
234-
235-
## Changelog
236-
237-
Please have a look at [`CHANGELOG.md`](CHANGELOG.md).
238-
239-
## Contributing
240-
241-
Please have a look at [`CONTRIBUTING.md`](.github/CONTRIBUTING.md).
242-
243-
:bulb: Do you want to add a rule for personal use or use in your organization? Instead of opening a pull request here, perhaps consider creating a new package based on [`ergebnis/php-cs-fixer-config-template`](https://github.com/ergebnis/php-cs-fixer-config-template), a GitHub repository template that provides a good starting point for creating and sharing your own rule sets.
244-
245-
## Code of Conduct
246-
247-
Please have a look at [`CODE_OF_CONDUCT.md`](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).
248-
249-
## License
250-
251-
This package is licensed using the MIT License.
252-
253-
Please have a look at [`LICENSE.md`](LICENSE.md).
254-
255-
## Credits
256-
257-
This project is inspired by and also replaces [`localheinz/php-cs-fixer-config`](https://github.com/localheinz/php-cs-fixer-config).
258-
259-
## Curious what I am building?
260-
261-
:mailbox_with_mail: [Subscribe to my list](https://localheinz.com/projects/), and I will occasionally send you an email to let you know what I am working on.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"autoload": {
1212
"psr-4": {
13-
"SzpeViktor\\PhpCsFixer\\Laravel\\": "src"
13+
"SzepeViktor\\PhpCsFixer\\Laravel\\": "src/"
1414
}
1515
},
1616
"config": {

src/ConfigurationFactory.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SzepeViktor\PhpCsFixer\Laravel;
6+
7+
class ConfigurationFactory
8+
{
9+
public static function preset(array $array): array
10+
{
11+
return $array;
12+
}
13+
}

src/Factory.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,25 @@
22

33
declare(strict_types=1);
44

5-
/**
6-
* Copyright (c) 2019-2022 Andreas Möller
7-
*
8-
* For the full copyright and license information, please view
9-
* the LICENSE.md file that was distributed with this source code.
10-
*
11-
* @see https://github.com/ergebnis/php-cs-fixer-config
12-
*/
13-
14-
namespace Ergebnis\PhpCsFixer\Config;
5+
namespace SzepeViktor\PhpCsFixer\Laravel;
156

167
use PhpCsFixer\Config;
8+
use SzepeViktor\PhpCsFixer\Laravel\RuleSet\Laravel;
179

1810
final class Factory
1911
{
2012
/**
21-
* Creates a configuration based on a rule set.
22-
*
2313
* @param array<string, array|bool> $overrideRules
24-
*
25-
* @throws \RuntimeException
2614
*/
27-
public static function fromRuleSet(RuleSet $ruleSet, array $overrideRules = []): Config
15+
public static function fromLaravelRuleSet(array $overrideRules = []): Config
2816
{
29-
if (\PHP_VERSION_ID < $ruleSet->targetPhpVersion()) {
30-
throw new \RuntimeException(\sprintf(
31-
'Current PHP version "%s" is less than targeted PHP version "%s".',
32-
\PHP_VERSION_ID,
33-
$ruleSet->targetPhpVersion(),
34-
));
35-
}
36-
37-
$config = new Config($ruleSet->name());
17+
$ruleSet = new Laravel();
18+
$config = new Config('Laravel');
3819

3920
$config->setRiskyAllowed(true);
4021
$config->setRules(\array_merge(
41-
$ruleSet->rules(),
42-
$overrideRules,
22+
$ruleSet->getRules(),
23+
$overrideRules
4324
));
4425

4526
return $config;

0 commit comments

Comments
 (0)