Skip to content

Commit 235ac7f

Browse files
authored
Replace StyleCI to PHP CS Fixer (#108)
1 parent f0a70d4 commit 235ac7f

File tree

64 files changed

+245
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+245
-339
lines changed

.github/workflows/cs.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: cs fixer
2+
3+
on:
4+
pull_request_target:
5+
paths-ignore:
6+
- 'docs/**'
7+
- 'README.md'
8+
- 'CHANGELOG.md'
9+
- '.gitignore'
10+
- '.gitattributes'
11+
- 'infection.json.dist'
12+
- 'psalm.xml'
13+
14+
jobs:
15+
fix:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
ref: ${{ github.head_ref }}
24+
repository: ${{ github.event.pull_request.head.repo.full_name }}
25+
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
26+
27+
- name: Install PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: 8.4
31+
tools: composer:v2
32+
coverage: none
33+
34+
- name: Install Composer dependencies
35+
uses: "ramsey/composer-install@v3"
36+
37+
- name: Run Rector
38+
run: compose
39+
40+
- name: Run PHP CS Fixer
41+
run: composer php-cs-fixer
42+
43+
- name: Commit changes
44+
uses: stefanzweifel/git-auto-commit-action@v5
45+
with:
46+
commit_message: "Apply PHP CS Fixer and Rector changes (CI)"
47+
file_pattern: '*.php'
48+
disable_globbing: true

.github/workflows/rector.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ composer.phar
2626
/phpunit.phar
2727
/phpunit.xml
2828
/.phpunit.cache
29+
30+
# PHP CS Fixer
31+
/.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
8+
9+
$finder = (new Finder())->in([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
12+
]);
13+
14+
return (new Config())
15+
->setParallelConfig(ParallelConfigFactory::detect())
16+
->setRules([
17+
'@PER-CS2.0' => true,
18+
'no_unused_imports' => true,
19+
])
20+
->setFinder($finder);

.styleci.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"psr/container": "^1.0 || ^2.0"
3131
},
3232
"require-dev": {
33+
"friendsofphp/php-cs-fixer": "^3.69",
3334
"maglnet/composer-require-checker": "^4.7.1",
3435
"phpunit/phpunit": "^10.5.45",
3536
"rector/rector": "^2.0.9",
@@ -57,6 +58,8 @@
5758
}
5859
},
5960
"scripts": {
61+
"php-cs-fixer": "php-cs-fixer fix",
62+
"rector": "rector",
6063
"test": "phpunit --testdox --no-interaction",
6164
"test-watch": "phpunit-watcher watch"
6265
}

docs/internals.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static
2727

2828
## Code style
2929

30-
Use [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or
31-
use either newest or any specific version of PHP:
30+
Package used [PHP CS Fixer](https://cs.symfony.com/) to maintain [PER CS 2.0](https://www.php-fig.org/per/coding-style/)
31+
code style and [Rector](https://github.com/rectorphp/rector) to make codebase follow some specific rules or use either
32+
newest or any specific version of PHP:
3233

3334
```shell
34-
./vendor/bin/rector
35+
composer php-cs-fixer
36+
composer rector
3537
```
3638

3739
## Dependencies

src/ArrayDefinition.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ final class ArrayDefinition implements DefinitionInterface
4848
private function __construct(
4949
private string $class,
5050
private array $constructorArguments,
51-
private array $methodsAndProperties
52-
) {
53-
}
51+
private array $methodsAndProperties,
52+
) {}
5453

5554
/**
5655
* @param ContainerInterface|null $referenceContainer Container to resolve references with.
@@ -72,7 +71,7 @@ public static function fromConfig(array $config): self
7271
return new self(
7372
$config[self::CLASS_NAME],
7473
$config[self::CONSTRUCTOR] ?? [],
75-
self::getMethodsAndPropertiesFromConfig($config)
74+
self::getMethodsAndPropertiesFromConfig($config),
7675
);
7776
}
7877

@@ -142,7 +141,7 @@ public function resolve(ContainerInterface $container): object
142141
$resolvedConstructorArguments = $this->resolveFunctionArguments(
143142
$container,
144143
DefinitionExtractor::fromClassName($class),
145-
$this->getConstructorArguments()
144+
$this->getConstructorArguments(),
146145
);
147146

148147
/** @psalm-suppress MixedMethodCall */
@@ -182,7 +181,7 @@ public function resolve(ContainerInterface $container): object
182181
private function resolveFunctionArguments(
183182
ContainerInterface $container,
184183
array $dependencies,
185-
array $arguments
184+
array $arguments,
186185
): array {
187186
$isIntegerIndexed = $this->isIntegerIndexed($arguments);
188187
$dependencyIndex = 0;
@@ -209,7 +208,7 @@ private function resolveFunctionArguments(
209208
$arguments[$variadicKey] = DefinitionResolver::resolve(
210209
$container,
211210
$this->referenceContainer,
212-
$arguments[$variadicKey]
211+
$arguments[$variadicKey],
213212
);
214213
}
215214

@@ -220,8 +219,8 @@ private function resolveFunctionArguments(
220219
throw new InvalidArgumentException(
221220
sprintf(
222221
'Named argument for a variadic parameter should be an array, "%s" given.',
223-
gettype($arguments[$variadicKey])
224-
)
222+
gettype($arguments[$variadicKey]),
223+
),
225224
);
226225
}
227226
} else {
@@ -262,7 +261,7 @@ private function isIntegerIndexed(array $arguments): bool
262261
}
263262
if ($hasIntegerIndex && $hasStringIndex) {
264263
throw new InvalidConfigException(
265-
'Arguments indexed both by name and by position are not allowed in the same array.'
264+
'Arguments indexed both by name and by position are not allowed in the same array.',
266265
);
267266
}
268267

src/CallableDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function resolve(ContainerInterface $container): mixed
4545
{
4646
try {
4747
$reflection = new ReflectionFunction(
48-
$this->prepareClosure($this->callable, $container)
48+
$this->prepareClosure($this->callable, $container),
4949
);
5050
} catch (ReflectionException) {
5151
throw new NotInstantiableException(
52-
'Can not instantiate callable definition. Got ' . var_export($this->callable, true)
52+
'Can not instantiate callable definition. Got ' . var_export($this->callable, true),
5353
);
5454
}
5555

src/DefinitionStorage.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ final class DefinitionStorage
3232
*/
3333
public function __construct(
3434
private array $definitions = [],
35-
private readonly bool $useStrictMode = false
36-
) {
37-
}
35+
private readonly bool $useStrictMode = false,
36+
) {}
3837

3938
/**
4039
* @param ContainerInterface $delegateContainer Container to fall back to when dependency is not found.
@@ -113,7 +112,7 @@ private function isResolvable(string $id, array $building): bool
113112
throw new CircularReferenceException(sprintf(
114113
'Circular reference to "%s" detected while building: %s.',
115114
$id,
116-
implode(', ', array_keys($building))
115+
implode(', ', array_keys($building)),
117116
));
118117
}
119118

@@ -212,8 +211,8 @@ private function isResolvable(string $id, array $building): bool
212211
sprintf(
213212
'Circular reference to "%s" detected while building: %s.',
214213
$id,
215-
implode(', ', array_keys($building))
216-
)
214+
implode(', ', array_keys($building)),
215+
),
217216
);
218217
}
219218

0 commit comments

Comments
 (0)