Skip to content

Commit 30566f6

Browse files
authored
Replace StyleCI with PHP CS Fixer (#220)
1 parent d9a1507 commit 30566f6

33 files changed

+197
-273
lines changed

.github/workflows/rector-cs.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Rector + PHP CS Fixer
2+
3+
on:
4+
pull_request_target:
5+
paths:
6+
- 'src/**'
7+
- 'tests/**'
8+
- '.github/workflows/rector-cs.yml'
9+
- 'composer.json'
10+
- 'rector.php'
11+
- '.php-cs-fixer.dist.php'
12+
13+
permissions:
14+
contents: read
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
rector:
22+
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
23+
secrets:
24+
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
25+
with:
26+
repository: ${{ github.event.pull_request.head.repo.full_name }}
27+
php: '8.0'

.github/workflows/rector.yml

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

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ phpunit.phar
3030
# phpunit cache
3131
.phpunit.result.cache
3232

33-
33+
# PHP CS Fixer
34+
/.php-cs-fixer.cache
35+
/.php-cs-fixer.php

.php-cs-fixer.dist.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
// TODO: Update the configuration after raising the minimum PHP version
15+
return (new Config())
16+
->setRiskyAllowed(true)
17+
->setParallelConfig(ParallelConfigFactory::detect())
18+
->setRules([
19+
'@PER-CS2.0' => true,
20+
'nullable_type_declaration' => true,
21+
'operator_linebreak' => true,
22+
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
23+
'single_class_element_per_statement' => true,
24+
'types_spaces' => true,
25+
'no_unused_imports' => true,
26+
'ordered_class_elements' => true,
27+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
28+
'declare_strict_types' => true,
29+
'native_function_invocation' => true,
30+
'native_constant_invocation' => true,
31+
'fully_qualified_strict_types' => [
32+
'import_symbols' => true
33+
],
34+
'global_namespace_import' => [
35+
'import_classes' => true,
36+
'import_constants' => true,
37+
'import_functions' => true,
38+
],
39+
])
40+
->setFinder($finder);

.styleci.yml

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

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.3.2 under development
44

5-
- no changes in this release.
5+
- Enh #220: Explicitly import functions in "use" section (@mspirkov)
66

77
## 1.3.1 December 02, 2025
88

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"require-dev": {
3434
"bamarni/composer-bin-plugin": "^1.8.3",
35+
"friendsofphp/php-cs-fixer": "^3.66",
3536
"maglnet/composer-require-checker": "^4.4",
3637
"phpunit/phpunit": "^9.6.22",
3738
"rector/rector": "^2.0.10",

src/Factory.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class Factory
3434
public function __construct(
3535
?ContainerInterface $container = null,
3636
array $definitions = [],
37-
private bool $validate = true
37+
private bool $validate = true,
3838
) {
3939
$this->validateDefinitions($definitions);
4040
$this->internalContainer = new FactoryInternalContainer($container, $definitions);
@@ -54,21 +54,6 @@ public function withDefinitions(array $definitions): self
5454
return $new;
5555
}
5656

57-
/**
58-
* @param array $definitions Definitions to validate.
59-
* @psalm-param array<string, mixed> $definitions
60-
*
61-
* @throws InvalidConfigException
62-
*/
63-
private function validateDefinitions(array $definitions): void
64-
{
65-
if ($this->validate) {
66-
foreach ($definitions as $id => $definition) {
67-
DefinitionValidator::validate($definition, $id);
68-
}
69-
}
70-
}
71-
7257
/**
7358
* Creates a new object using the given configuration.
7459
*
@@ -140,6 +125,21 @@ public function create(mixed $config): mixed
140125
return $this->internalContainer->create($definition);
141126
}
142127

128+
/**
129+
* @param array $definitions Definitions to validate.
130+
* @psalm-param array<string, mixed> $definitions
131+
*
132+
* @throws InvalidConfigException
133+
*/
134+
private function validateDefinitions(array $definitions): void
135+
{
136+
if ($this->validate) {
137+
foreach ($definitions as $id => $definition) {
138+
DefinitionValidator::validate($definition, $id);
139+
}
140+
}
141+
}
142+
143143
/**
144144
* @throws InvalidConfigException
145145
*/
@@ -155,7 +155,7 @@ private function createDefinition(mixed $config): DefinitionInterface
155155
) {
156156
$definition = $this->mergeDefinitions(
157157
$containerDefinition,
158-
$definition
158+
$definition,
159159
);
160160
}
161161

src/FactoryInternalContainer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use function array_key_exists;
1919
use function is_object;
2020
use function is_string;
21+
use function sprintf;
2122

2223
/**
2324
* Factory's primary container.
@@ -42,9 +43,8 @@ final class FactoryInternalContainer implements ContainerInterface
4243
*/
4344
public function __construct(
4445
private ?ContainerInterface $container,
45-
private array $definitions
46-
) {
47-
}
46+
private array $definitions,
47+
) {}
4848

4949
/**
5050
* @param array<string, mixed> $definitions Definitions to create objects with.
@@ -117,14 +117,14 @@ public function getDefinition(string $id): DefinitionInterface
117117
) {
118118
$this->definitionInstances[$id] = $this->getDefinition($this->definitions[$id]);
119119
} else {
120-
$this->definitionInstances[$id] =
121-
(is_string($this->definitions[$id]) && class_exists($this->definitions[$id]))
120+
$this->definitionInstances[$id]
121+
= (is_string($this->definitions[$id]) && class_exists($this->definitions[$id]))
122122
? ArrayDefinition::fromPreparedData($this->definitions[$id])
123123
: Normalizer::normalize($this->definitions[$id], $id);
124124
}
125125
} else {
126126
throw new LogicException(
127-
sprintf('No definition found for "%s".', $id)
127+
sprintf('No definition found for "%s".', $id),
128128
);
129129
}
130130
}
@@ -157,8 +157,8 @@ private function build(string $id): mixed
157157
sprintf(
158158
'Circular reference to "%s" detected while creating: %s.',
159159
$id,
160-
implode(', ', array_keys($this->creatingIds))
161-
)
160+
implode(', ', array_keys($this->creatingIds)),
161+
),
162162
);
163163
}
164164

src/NotFoundException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Exception;
88
use Psr\Container\NotFoundExceptionInterface;
99

10+
use function sprintf;
11+
1012
/**
1113
* NotFoundException is thrown when no definition or class was found in the factory for a given ID.
1214
*/
@@ -16,7 +18,7 @@ final class NotFoundException extends Exception implements NotFoundExceptionInte
1618
* @param string $id ID of the definition or name of the class that was not found.
1719
*/
1820
public function __construct(
19-
private string $id
21+
private string $id,
2022
) {
2123
parent::__construct(sprintf('No definition or class found or resolvable for %s.', $id));
2224
}

0 commit comments

Comments
 (0)