Skip to content

Commit 85e2263

Browse files
authored
Drop PHP 7.4 support, Fix Doctrine Entities by Attributes (#17)
1 parent 57909e2 commit 85e2263

File tree

9 files changed

+70
-28
lines changed

9 files changed

+70
-28
lines changed

.github/workflows/integrate.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
php-version:
18-
- "7.4"
18+
- "8.0"
1919

2020
steps:
2121
- name: "Checkout"
@@ -62,8 +62,8 @@ jobs:
6262
strategy:
6363
matrix:
6464
php-version:
65-
- "7.4"
6665
- "8.0"
66+
- "8.1"
6767

6868
steps:
6969
- name: "Checkout"
@@ -72,7 +72,7 @@ jobs:
7272
- name: "Install PHP"
7373
uses: "shivammathur/setup-php@v2"
7474
with:
75-
coverage: "xdebug"
75+
coverage: "pcov"
7676
php-version: "${{ matrix.php-version }}"
7777
ini-values: zend.assertions=1
7878

@@ -95,6 +95,7 @@ jobs:
9595
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"
9696

9797
- name: "Send code coverage report to Codecov.io"
98+
if: ${{ matrix.php-version == '8.1' }}
9899
uses: codecov/codecov-action@v1
99100
with:
100101
token: ${{ secrets.CODECOV_TOKEN }}
@@ -109,7 +110,7 @@ jobs:
109110
strategy:
110111
matrix:
111112
php-version:
112-
- "7.4"
113+
- "8.0"
113114

114115
steps:
115116
- name: "Checkout"
@@ -146,7 +147,7 @@ jobs:
146147
strategy:
147148
matrix:
148149
php-version:
149-
- "7.4"
150+
- "8.0"
150151

151152
steps:
152153
- name: "Checkout"

composer.json

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,18 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.4 || ^8.0",
13+
"php": "~8.0.0 || ~8.1.0",
1414
"ext-mbstring": "*",
1515
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^3.1.0"
16+
"friendsofphp/php-cs-fixer": "^3.8.0"
1717
},
1818
"require-dev": {
1919
"malukenho/mcbumpface": "^1.1.5",
20-
"phpstan/phpstan": "^0.12.99",
21-
"phpstan/phpstan-phpunit": "^0.12.22",
22-
"phpunit/phpunit": "^9.5.9",
20+
"phpstan/phpstan": "^1.7.6",
21+
"phpstan/phpstan-phpunit": "^1.1.1",
22+
"phpunit/phpunit": "^9.5.20",
2323
"slam/php-debug-r": "^1.7.0",
24-
"slam/phpstan-extensions": "^5.1.0",
25-
"thecodingmachine/phpstan-strict-rules": "^0.12.1"
26-
},
27-
"extra": {
28-
"mc-bumpface": {
29-
"stripVersionPrefixes": true
30-
}
24+
"slam/phpstan-extensions": "^6.0.0"
3125
},
3226
"autoload": {
3327
"psr-4": {
@@ -38,5 +32,15 @@
3832
"psr-4": {
3933
"SlamCsFixer\\Tests\\": "tests/"
4034
}
35+
},
36+
"config": {
37+
"allow-plugins": {
38+
"malukenho/mcbumpface": true
39+
}
40+
},
41+
"extra": {
42+
"mc-bumpface": {
43+
"stripVersionPrefixes": true
44+
}
4145
}
4246
}

lib/Config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ final class Config extends PhpCsFixerConfig
1111
{
1212
public const RULES = [
1313
'@DoctrineAnnotation' => true,
14-
'@PHP80Migration' => true,
1514
'@PHP80Migration:risky' => true,
15+
'@PHP81Migration' => true,
1616
'@PHPUnit84Migration:risky' => true,
1717
'@PhpCsFixer' => true,
1818
'@PhpCsFixer:risky' => true,
@@ -29,6 +29,8 @@ final class Config extends PhpCsFixerConfig
2929
'combine_consecutive_unsets' => false,
3030
'comment_to_phpdoc' => false,
3131
'concat_space' => ['spacing' => 'one'],
32+
'control_structure_continuation_position' => true,
33+
'date_time_create_from_format_call' => true,
3234
'date_time_immutable' => false,
3335
'declare_parentheses' => true,
3436
'error_suppression' => false,

lib/FinalInternalClassFixer.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpCsFixer\FixerDefinition\CodeSample;
88
use PhpCsFixer\FixerDefinition\FixerDefinition;
99
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
10+
use PhpCsFixer\Tokenizer\CT;
1011
use PhpCsFixer\Tokenizer\Token;
1112
use PhpCsFixer\Tokenizer\Tokens;
1213
use SplFileInfo;
@@ -47,8 +48,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
4748
}
4849

4950
// ignore class if it's a Doctrine Entity
50-
$docToken = $tokens[$tokens->getPrevNonWhitespace($classIndex)];
51-
if ($docToken->isGivenKind(\T_DOC_COMMENT) && false !== \mb_strpos($docToken->getContent(), '@ORM\Entity')) {
51+
if (self::isDoctrineEntity($tokens, $classIndex)) {
5252
continue;
5353
}
5454

@@ -61,4 +61,31 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
6161
);
6262
}
6363
}
64+
65+
private static function isDoctrineEntity(Tokens $tokens, int $classIndex): bool
66+
{
67+
$docToken = $tokens[$tokens->getPrevNonWhitespace($classIndex)];
68+
if ($docToken->isGivenKind(\T_DOC_COMMENT) && false !== \mb_strpos($docToken->getContent(), '@ORM\Entity')) {
69+
return true;
70+
}
71+
72+
while ($classIndex > 0 && $tokens[$tokens->getPrevNonWhitespace($classIndex)]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
73+
$attributeOpenIndex = $tokens->getPrevTokenOfKind($classIndex, [[\T_ATTRIBUTE]]);
74+
\assert(null !== $attributeOpenIndex);
75+
$content = '';
76+
for ($index = $attributeOpenIndex; $index < $classIndex; ++$index) {
77+
$content .= $tokens[$index]->getContent();
78+
}
79+
if (false !== \mb_strpos($content, '#[ORM\Entity]')) {
80+
return true;
81+
}
82+
if (false !== \mb_strpos($content, '#[\Doctrine\ORM\Mapping\Entity')) {
83+
return true;
84+
}
85+
86+
$classIndex = $attributeOpenIndex - 1;
87+
}
88+
89+
return false;
90+
}
6491
}

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
includes:
2-
- phar://phpstan.phar/conf/config.level5.neon
32
- vendor/phpstan/phpstan-phpunit/extension.neon
43
- vendor/slam/phpstan-extensions/conf/slam-rules.neon
54

65
parameters:
6+
level: 5
77
paths:
88
- lib/
99
- tests/

tests/AbstractFixerTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ final protected function doTest($expected, $input = null, ?SplFileInfo $file = n
103103

104104
Tokens::clearCache();
105105
$expectedTokens = Tokens::fromCode($expected);
106-
static::assertTokens($expectedTokens, $tokens);
106+
self::assertTokens($expectedTokens, $tokens);
107107
}
108108

109109
static::assertNull($this->lintSource($expected));

tests/ConfigTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
*/
2020
final class ConfigTest extends TestCase
2121
{
22-
private ?array $setDefinitions;
23-
2422
public function testConfig(): void
2523
{
2624
$config = new Config();
@@ -32,6 +30,7 @@ public function testConfig(): void
3230
public function testAllRulesAreSpecifiedAndDifferentFromRuleSets(): void
3331
{
3432
$config = new Config();
33+
3534
/** @var array<string, mixed> $configRules */
3635
$configRules = $config->getRules();
3736
$ruleSet = new RuleSet($configRules);

tests/FinalInternalClassFixerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public function provideCases(): array
4242
[
4343
"<?php\n/**\n * @ORM\\Entity\n */\nclass MyEntity {}",
4444
],
45+
[
46+
"<?php\n#[ORM\\Entity]\nclass MyEntity {}",
47+
],
48+
[
49+
"<?php\n#[ORM\\Entity]\n#[CustomAttribute]\nclass MyEntity {}",
50+
],
51+
[
52+
"<?php\n#[\\Doctrine\\ORM\\Mapping\\Entity(repositoryClass: \\MyClass::class)]\nclass MyEntity {}",
53+
],
4554
[
4655
'<?php abstract class MyAbstract {}',
4756
],

tests/PhpFileOnlyProxyFixerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public function testGetDefinitionIsProxied(): void
8484

8585
$proxy = new PhpFileOnlyProxyFixer($fixer);
8686

87-
$fixerDefinition = $this->createMock(FixerDefinitionInterface::class);
88-
$fixerDefinition->expects(self::once())->method('getSummary')->willReturn($summary = \uniqid('summary'));
89-
$fixerDefinition->expects(self::once())->method('getCodeSamples')->willReturn($codeSamples = []);
90-
$fixerDefinition->expects(self::once())->method('getDescription')->willReturn($description = \uniqid('description'));
87+
$fixerDefinition = $this->createMock(FixerDefinitionInterface::class);
88+
$fixerDefinition->expects(self::once())->method('getSummary')->willReturn($summary = \uniqid('summary'));
89+
$fixerDefinition->expects(self::once())->method('getCodeSamples')->willReturn($codeSamples = []);
90+
$fixerDefinition->expects(self::once())->method('getDescription')->willReturn($description = \uniqid('description'));
9191
$fixerDefinition->expects(self::once())->method('getRiskyDescription')->willReturn($riskyDescription = \uniqid('riskyDescription'));
9292

9393
$fixer

0 commit comments

Comments
 (0)