Skip to content

Commit 9745387

Browse files
#274: Applied code quality tools
1 parent 88e092f commit 9745387

7 files changed

Lines changed: 66 additions & 74 deletions

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
},
1515
"require-dev": {
1616
"doctrine/orm": "^2.7",
17-
"friendsofphp/php-cs-fixer": "^3.58",
17+
"friendsofphp/php-cs-fixer": "^3.93",
1818
"maglnet/composer-require-checker": "^4.17",
19-
"phpstan/extension-installer": "^1.3",
20-
"phpstan/phpstan": "^1.11",
21-
"phpstan/phpstan-doctrine": "^1.4",
22-
"phpstan/phpstan-phpunit": "^1.4",
23-
"phpstan/phpstan-symfony": "^1.4",
19+
"phpstan/extension-installer": "^1.4",
20+
"phpstan/phpstan": "^2.1",
21+
"phpstan/phpstan-doctrine": "^2.0",
22+
"phpstan/phpstan-phpunit": "^2.0",
23+
"phpstan/phpstan-symfony": "^2.0",
2424
"phpunit/phpunit": "^10.5",
25-
"rector/rector": "^1.1"
25+
"rector/rector": "^2.3"
2626
},
2727
"suggest": {
2828
"darkwebdesign/symfony-addon-pack": "All Symfony add-ons bundled together",

phpstan.dist.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ parameters:
44
paths:
55
- 'src'
66
- 'tests'
7+
8+
treatPhpDocTypesAsCertain: false

rector.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6-
use Rector\Set\ValueObject\LevelSetList;
76

87
return RectorConfig::configure()
98
->withPaths([
109
__DIR__ . '/src',
1110
__DIR__ . '/tests',
1211
])
13-
->withSets([
14-
LevelSetList::UP_TO_PHP_82,
15-
])
16-
->withImportNames(
17-
importShortClasses: false,
18-
);
12+
->withPhpSets()
13+
->withAttributesSets()
14+
->withPreparedSets(phpunitCodeQuality: true, doctrineCodeQuality: true, symfonyCodeQuality: true, symfonyConfigs: true)
15+
->withComposerBased(doctrine: true, phpunit: true, symfony: true)
16+
->withImportNames(importShortClasses: false, removeUnusedImports: true)
17+
->withTypeCoverageLevel(0)
18+
->withDeadCodeLevel(0)
19+
->withCodeQualityLevel(0);

src/BooleanToValueTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* @template R of string|int|float|bool
3131
*
32-
* @template-implements DataTransformerInterface<bool, R>
32+
* @implements DataTransformerInterface<bool, R>
3333
*
3434
* @author Raymond Schouten
3535
*

src/EntityToIdentifierTransformer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* @template T of object
4141
* @template R of mixed
4242
*
43-
* @template-implements DataTransformerInterface<T, R>
43+
* @implements DataTransformerInterface<T, R>
4444
*
4545
* @author Raymond Schouten
4646
*
@@ -52,6 +52,7 @@ class EntityToIdentifierTransformer implements DataTransformerInterface
5252
private readonly string $className;
5353
/** @var ObjectRepository<T> */
5454
private readonly ObjectRepository $repository;
55+
/** @var ClassMetadata<T> */
5556
private readonly ClassMetadata $metadata;
5657

5758
/**

tests/BooleanToValueTransformerTest.php

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @internal
3434
*/
3535
#[CoversClass(BooleanToValueTransformer::class)]
36-
class BooleanToValueTransformerTest extends TestCase
36+
final class BooleanToValueTransformerTest extends TestCase
3737
{
3838
#[DataProvider('providerTrueFalseValue')]
3939
public function testTransform(mixed $trueValue, mixed $falseValue): void
@@ -125,46 +125,40 @@ public function testReverseTransformInvalidValue(mixed $trueValue, mixed $falseV
125125
}
126126

127127
/**
128-
* @return array<string, array{mixed, mixed}>
128+
* @return \Iterator<string, array{mixed, mixed}>
129129
*/
130-
public static function providerTrueFalseValue(): array
130+
public static function providerTrueFalseValue(): \Iterator
131131
{
132-
return [
133-
'true/false' => [true, false],
134-
'yes/no' => ['yes', 'no'],
135-
'on/off' => ['on', 'off'],
136-
'1/0' => ['1', '0'],
137-
'1/2' => [1, 2],
138-
'1.3/2.7' => [1.3, 2.7],
139-
];
132+
yield 'true/false' => [true, false];
133+
yield 'yes/no' => ['yes', 'no'];
134+
yield 'on/off' => ['on', 'off'];
135+
yield '1/0' => ['1', '0'];
136+
yield '1/2' => [1, 2];
137+
yield '1.3/2.7' => [1.3, 2.7];
140138
}
141139

142140
/**
143-
* @return array<string, array{mixed}>
141+
* @return \Iterator<string, array{mixed}>
144142
*/
145-
public static function providerNoBool(): array
143+
public static function providerNoBool(): \Iterator
146144
{
147-
return [
148-
'int' => [1],
149-
'float' => [1.2],
150-
'string' => ['foo'],
151-
'array' => [['foo', 'bar']],
152-
'object' => [new \stdClass()],
153-
'resource' => [tmpfile()],
154-
'callable' => [function () {}],
155-
];
145+
yield 'int' => [1];
146+
yield 'float' => [1.2];
147+
yield 'string' => ['foo'];
148+
yield 'array' => [['foo', 'bar']];
149+
yield 'object' => [new \stdClass()];
150+
yield 'resource' => [tmpfile()];
151+
yield 'callable' => [function (): void {}];
156152
}
157153

158154
/**
159-
* @return array<string, array{mixed}>
155+
* @return \Iterator<string, array{mixed}>
160156
*/
161-
public static function providerNoScalar(): array
157+
public static function providerNoScalar(): \Iterator
162158
{
163-
return [
164-
'array' => [['foo', 'bar']],
165-
'object' => [new \stdClass()],
166-
'resource' => [tmpfile()],
167-
'callable' => [function () {}],
168-
];
159+
yield 'array' => [['foo', 'bar']];
160+
yield 'object' => [new \stdClass()];
161+
yield 'resource' => [tmpfile()];
162+
yield 'callable' => [function (): void {}];
169163
}
170164
}

tests/EntityToIdentifierTransformerTest.php

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* @internal
4141
*/
4242
#[CoversClass(EntityToIdentifierTransformer::class)]
43-
class EntityToIdentifierTransformerTest extends TestCase
43+
final class EntityToIdentifierTransformerTest extends TestCase
4444
{
4545
private City $entity;
4646
/** @var class-string<City|AbstractPerson|Employee> */
@@ -52,8 +52,6 @@ class EntityToIdentifierTransformerTest extends TestCase
5252
private ObjectManager $entityManager;
5353
/** @var ObjectRepository<City>&MockObject */
5454
private ObjectRepository $repository;
55-
/** @var ClassMetadata&MockObject */
56-
private ClassMetadata $metadata;
5755

5856
protected function setUp(): void
5957
{
@@ -66,13 +64,13 @@ protected function setUp(): void
6664

6765
$this->entityManager = $this->createMock(ObjectManager::class);
6866
$this->repository = $this->createMock(ObjectRepository::class);
69-
$this->metadata = $this->createMock(ClassMetadata::class);
67+
$metadata = $this->createMock(ClassMetadata::class);
7068

7169
$this->entityManager->method('getRepository')->willReturn($this->repository);
72-
$this->entityManager->method('getClassMetadata')->willReturn($this->metadata);
70+
$this->entityManager->method('getClassMetadata')->willReturn($metadata);
7371

74-
$this->metadata->method('getName')->willReturnCallback($this->getClassName(...));
75-
$this->metadata->method('getIdentifierValues')->willReturnCallback($this->getIdentifier(...));
72+
$metadata->method('getName')->willReturnCallback($this->getClassName(...));
73+
$metadata->method('getIdentifierValues')->willReturnCallback($this->getIdentifier(...));
7674
}
7775

7876
public function getClassName(): string
@@ -100,7 +98,7 @@ public function testTransform(): void
10098
public function testTransformAlias(): void
10199
{
102100
/** @var class-string<City> $className */
103-
$className = 'AppBundle:City';
101+
$className = 'AppBundle:City'; // @phpstan-ignore varTag.nativeType
104102

105103
$transformer = new EntityToIdentifierTransformer($this->entityManager, $className);
106104

@@ -222,31 +220,27 @@ public function testReverseTransformEntityNotFound(): void
222220
}
223221

224222
/**
225-
* @return array<string, array{mixed}>
223+
* @return \Iterator<string, array{mixed}>
226224
*/
227-
public static function providerNoObject(): array
225+
public static function providerNoObject(): \Iterator
228226
{
229-
return [
230-
'bool' => [true],
231-
'int' => [1],
232-
'float' => [1.2],
233-
'string' => ['foo'],
234-
'array' => [['foo', 'bar']],
235-
'resource' => [tmpfile()],
236-
'callable' => [function () {}],
237-
];
227+
yield 'bool' => [true];
228+
yield 'int' => [1];
229+
yield 'float' => [1.2];
230+
yield 'string' => ['foo'];
231+
yield 'array' => [['foo', 'bar']];
232+
yield 'resource' => [tmpfile()];
233+
yield 'callable' => [function (): void {}];
238234
}
239235

240236
/**
241-
* @return array<string, array{mixed}>
237+
* @return \Iterator<string, array{mixed}>
242238
*/
243-
public static function providerNoScalar(): array
244-
{
245-
return [
246-
'array' => [['foo', 'bar']],
247-
'object' => [new \stdClass()],
248-
'resource' => [tmpfile()],
249-
'callable' => [function () {}],
250-
];
239+
public static function providerNoScalar(): \Iterator
240+
{
241+
yield 'array' => [['foo', 'bar']];
242+
yield 'object' => [new \stdClass()];
243+
yield 'resource' => [tmpfile()];
244+
yield 'callable' => [function (): void {}];
251245
}
252246
}

0 commit comments

Comments
 (0)