Skip to content

Commit e18db17

Browse files
Allow Symfony 8 and remove PHP_CodeSniffer. Clean up coding standard.
1 parent 88b595e commit e18db17

7 files changed

Lines changed: 51 additions & 57 deletions

File tree

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060

6161
# PHPStan
6262
- name: Run PHPStan
63-
run: vendor/bin/phpstan analyse -c phpstan.neon
63+
run: vendor/bin/phpstan analyse -c phpstan.neon --level 1
6464

6565
# Upload coverage to Codecov
6666
- name: Upload coverage to Codecov

composer.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"extra": {
66
"symfony": {
77
"allow-contrib": false,
8-
"require": "7.3.*"
8+
"require": "^7.3 || ^8.0"
99
}
1010
},
1111
"keywords": [
@@ -25,32 +25,29 @@
2525
"php": ">=8.4",
2626
"doctrine/doctrine-bundle": "^2.18.1",
2727
"doctrine/orm": "^3.5.7",
28-
"symfony/framework-bundle": "^v7.3.6",
29-
"symfony/security-bundle": "^v7.3.4",
30-
"symfony/yaml": "^v7.3.5",
31-
"symfony/property-access": "^v7.3.3",
32-
"twig/twig": "^v3.22.0",
28+
"symfony/framework-bundle": "^7.3 || ^8.0",
29+
"symfony/security-bundle": "^7.3 || ^8.0",
30+
"symfony/yaml": "^7.3 || ^8.0",
31+
"symfony/property-access": "^7.3 || ^8.0",
32+
"twig/twig": "^3.22.0",
3333
"symfony/translation-contracts": "^3.6.1",
3434
"ext-json": "*",
3535
"ext-mbstring": "*",
36-
"symfony/uid": "^7.3.1"
36+
"symfony/uid": "^7.3 || ^8.0"
3737
},
3838
"require-dev": {
3939
"roave/security-advisories": "dev-latest",
40-
"symfony/phpunit-bridge": "^7.3.4",
41-
"phpunit/phpunit": "^12.4.2",
40+
"symfony/phpunit-bridge": "^7.3 || ^8.0",
41+
"phpunit/phpunit": "^12.4.4",
4242
"php-parallel-lint/php-parallel-lint": "^v1.4.0",
4343
"friendsofphp/php-cs-fixer": "@stable",
44-
"dealerdirect/phpcodesniffer-composer-installer": "^1.2.0",
4544
"phpstan/phpstan": "^2.1.32",
4645
"phpstan/extension-installer": "^1.4.3",
4746
"phpstan/phpstan-deprecation-rules": "^2.0.3",
4847
"phpstan/phpstan-strict-rules": "^2.0.7",
4948
"phpstan/phpstan-symfony": "^2.0.8",
5049
"phpstan/phpstan-phpunit": "^2.0.8",
51-
"rector/rector": "^2.2.7",
52-
"phpcompatibility/php-compatibility": "^9.3.5",
53-
"slevomat/coding-standard": "^8.22.1",
50+
"rector/rector": "^2.2.9",
5451
"ext-pdo": "*",
5552
"ext-pdo_sqlite": "*",
5653
"ext-sqlite3": "*",
@@ -93,8 +90,7 @@
9390
},
9491
"config": {
9592
"allow-plugins": {
96-
"phpstan/extension-installer": true,
97-
"dealerdirect/phpcodesniffer-composer-installer": true
93+
"phpstan/extension-installer": true
9894
},
9995
"sort-packages": true
10096
}

src/Doctrine/Model/TranslatableInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
interface TranslatableInterface
1010
{
11+
public function generateTuuid(): void;
12+
1113
public function getTuuid(): Tuuid|null;
1214

1315
public function getLocale(): string|null;

src/Translation/EntityTranslator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ private function warmupTranslations(array $entities, string $locale): void
244244
$byClass[$entity::class][] = $tuuid->getValue();
245245
}
246246

247-
/** @var class-string<TranslatableInterface> $class */
248247
foreach ($byClass as $class => $tuuids) {
249248
if (!is_array($tuuids) || 0 === count($tuuids)) {
250249
// @codeCoverageIgnoreStart

tests/Translation/EntityTranslatorInterfaceTest.php

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,59 +31,55 @@ public function testInterfaceMethodsExist(): void
3131
}
3232
}
3333

34+
/**
35+
* @throws \ReflectionException
36+
*/
3437
public function testAfterLoadMethodSignature(): void
3538
{
36-
$reflection = new \ReflectionClass(EntityTranslatorInterface::class);
37-
$method = $reflection->getMethod('afterLoad');
38-
$parameters = $method->getParameters();
39-
40-
self::assertCount(1, $parameters);
41-
self::assertSame('entity', $parameters[0]->getName());
42-
43-
$type = $parameters[0]->getType();
44-
self::assertNotNull($type);
45-
self::assertEquals(TranslatableInterface::class, $type->getName());
39+
$this->assertParameterType('afterLoad');
4640
}
4741

42+
/**
43+
* @throws \ReflectionException
44+
*/
4845
public function testBeforePersistMethodSignature(): void
4946
{
50-
$reflection = new \ReflectionClass(EntityTranslatorInterface::class);
51-
$method = $reflection->getMethod('beforePersist');
52-
$parameters = $method->getParameters();
53-
54-
self::assertCount(1, $parameters);
55-
self::assertSame('entity', $parameters[0]->getName());
56-
57-
$entityType = $parameters[0]->getType();
58-
self::assertNotNull($entityType);
59-
self::assertEquals(TranslatableInterface::class, $entityType->getName());
47+
$this->assertParameterType('beforePersist');
6048
}
6149

50+
/**
51+
* @throws \ReflectionException
52+
*/
6253
public function testBeforeUpdateMethodSignature(): void
6354
{
64-
$reflection = new \ReflectionClass(EntityTranslatorInterface::class);
65-
$method = $reflection->getMethod('beforeUpdate');
66-
$parameters = $method->getParameters();
67-
68-
self::assertCount(1, $parameters);
69-
self::assertSame('entity', $parameters[0]->getName());
70-
71-
$entityType = $parameters[0]->getType();
72-
self::assertNotNull($entityType);
73-
self::assertEquals(TranslatableInterface::class, $entityType->getName());
55+
$this->assertParameterType('beforeUpdate');
7456
}
7557

58+
/**
59+
* @throws \ReflectionException
60+
*/
7661
public function testBeforeRemoveMethodSignature(): void
62+
{
63+
$this->assertParameterType('beforeRemove');
64+
}
65+
66+
/**
67+
* Helper to assert that a method parameter has the expected type.
68+
*
69+
* @throws \ReflectionException
70+
*/
71+
private function assertParameterType(string $methodName): void
7772
{
7873
$reflection = new \ReflectionClass(EntityTranslatorInterface::class);
79-
$method = $reflection->getMethod('beforeRemove');
74+
$method = $reflection->getMethod($methodName);
8075
$parameters = $method->getParameters();
8176

82-
self::assertCount(1, $parameters);
83-
self::assertSame('entity', $parameters[0]->getName());
77+
self::assertCount(0 + 1, $parameters);
78+
$param = $parameters[0];
79+
self::assertNotNull($param->getType(), sprintf('Parameter %s::$%s should have a type', EntityTranslatorInterface::class, $param->getName()));
8480

85-
$entityType = $parameters[0]->getType();
86-
self::assertNotNull($entityType);
87-
self::assertEquals(TranslatableInterface::class, $entityType->getName());
81+
$type = $param->getType();
82+
self::assertInstanceOf(\ReflectionNamedType::class, $type);
83+
self::assertSame(TranslatableInterface::class, $type->getName());
8884
}
8985
}

tests/Translation/Handlers/UnidirectionalManyToManyHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Common\Collections\Collection;
99
use Doctrine\ORM\Mapping\ClassMetadata;
1010
use Doctrine\ORM\Mapping\ManyToMany;
11+
use PHPUnit\Framework\Attributes\CoversClass;
1112
use Tmi\TranslationBundle\Fixtures\Entity\Scalar\Scalar;
1213
use Tmi\TranslationBundle\Fixtures\Entity\Translatable\TranslatableManyToManyBidirectionalParent;
1314
use Tmi\TranslationBundle\Fixtures\Entity\Translatable\TranslatableManyToManyUnidirectionalChild;
@@ -16,7 +17,7 @@
1617
use Tmi\TranslationBundle\Translation\Args\TranslationArgs;
1718
use Tmi\TranslationBundle\Translation\Handlers\UnidirectionalManyToManyHandler;
1819

19-
#[\PHPUnit\Framework\Attributes\CoversClass(UnidirectionalManyToManyHandler::class)]
20+
#[CoversClass(UnidirectionalManyToManyHandler::class)]
2021
final class UnidirectionalManyToManyHandlerTest extends UnitTestCase
2122
{
2223
/**

tests/Translation/UnitTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class UnitTestCase extends TestCase
2121

2222
protected EntityTranslator|null $translator = null;
2323

24-
protected EntityManagerInterface|null $entityManager = null;
24+
protected (MockObject&EntityManagerInterface)|null $entityManager = null;
2525

26-
protected EventDispatcherInterface|null $eventDispatcherInterface = null;
26+
protected (MockObject&EventDispatcherInterface)|null $eventDispatcherInterface = null;
2727

28-
protected AttributeHelper|null $attributeHelper = null;
28+
protected (MockObject&AttributeHelper)|null $attributeHelper = null;
2929

3030
protected PropertyAccessor|null $propertyAccessor = null;
3131

0 commit comments

Comments
 (0)