Skip to content

Commit eaa4279

Browse files
chore: upgrade PHPStan and Rector to v2 (#289)
1 parent d3c5b4b commit eaa4279

File tree

9 files changed

+29
-19
lines changed

9 files changed

+29
-19
lines changed

ci/phpstan/baselines/lexer-constants.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ parameters:
99
- '#Fetching deprecated class constant T_ORDER of class Doctrine\\ORM\\Query\\Lexer#'
1010
- '#Fetching deprecated class constant T_AS of class Doctrine\\ORM\\Query\\Lexer#'
1111
- '#Fetching deprecated class constant T_DISTINCT of class Doctrine\\ORM\\Query\\Lexer#'
12+
- '#Parameter \#1 \$token of method Doctrine\\ORM\\Query\\Parser::match\(\) expects Doctrine\\ORM\\Query\\TokenType, mixed given.#'
13+
- '#Parameter \#1 \$type of method Doctrine\\Common\\Lexer\\AbstractLexer<Doctrine\\ORM\\Query\\TokenType,string>::isNextToken\(\) expects Doctrine\\ORM\\Query\\TokenType, mixed given.#'

ci/phpstan/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ parameters:
2222

2323
errorFormat: table
2424
reportUnmatchedIgnoredErrors: false
25+
treatPhpDocTypesAsCertain: false

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
"require-dev": {
4646
"deptrac/deptrac": "^3.0",
4747
"doctrine/orm": "~2.14||~3.0",
48-
"ekino/phpstan-banned-code": "^1.0",
48+
"ekino/phpstan-banned-code": "^3.0",
4949
"friendsofphp/php-cs-fixer": "^3.72.0",
50-
"phpstan/phpstan": "^1.12.21",
51-
"phpstan/phpstan-deprecation-rules": "^1.2.1",
52-
"phpstan/phpstan-doctrine": "^1.5.7",
53-
"phpstan/phpstan-phpunit": "^1.4.2",
50+
"phpstan/phpstan": "^2.1",
51+
"phpstan/phpstan-deprecation-rules": "^2.0",
52+
"phpstan/phpstan-doctrine": "^2.0",
53+
"phpstan/phpstan-phpunit": "^2.0",
5454
"phpunit/phpunit": "^10.5.45",
55-
"rector/rector": "^1.2.10",
55+
"rector/rector": "^2.0",
5656
"symfony/cache": "^6.4||^7.0"
5757
},
5858
"suggest": {

src/MartinGeorgiev/Doctrine/DBAL/Types/BaseType.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
abstract class BaseType extends Type
1818
{
19-
protected const TYPE_NAME = null;
19+
/**
20+
* @var string
21+
*/
22+
protected const TYPE_NAME = '';
2023

2124
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
2225
{
@@ -42,7 +45,7 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool
4245

4346
private function throwExceptionIfTypeNameNotConfigured(): void
4447
{
45-
if (null === static::TYPE_NAME) {
48+
if (static::TYPE_NAME === '') {
4649
throw new \LogicException(\sprintf('Doctrine type defined in class %s has no meaningful value for TYPE_NAME constant', self::class));
4750
}
4851
}

src/MartinGeorgiev/Doctrine/DBAL/Types/TextArray.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
3838

3939
protected function transformToPostgresTextArray(array $phpTextArray): string
4040
{
41-
if (!\is_array($phpTextArray)) {
42-
throw new \InvalidArgumentException(\sprintf('Value %s is not an array', \var_export($phpTextArray, true)));
43-
}
44-
4541
if ($phpTextArray === []) {
4642
return '{}';
4743
}

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseFunction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ protected function feedParserWithNodes(Parser $parser): void
6464
$lastNode = $nodesMappingCount - 1;
6565
for ($i = 0; $i < $nodesMappingCount; $i++) {
6666
$parserMethod = $this->nodesMapping[$i];
67+
// @phpstan-ignore-next-line
6768
$this->nodes[$i] = $parser->{$parserMethod}();
6869
if ($i < $lastNode) {
6970
$parser->match(\class_exists(TokenType::class) ? TokenType::T_COMMA : Lexer::T_COMMA);

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ protected function feedParserWithNodes(Parser $parser): void
2828
$lexer = $parser->getLexer();
2929

3030
try {
31+
// @phpstan-ignore-next-line
3132
$this->nodes[] = $parser->{$this->commonNodeMapping}();
3233
if ($lexer->lookahead?->type === null) {
3334
throw ParserException::missingLookaheadType();
@@ -42,6 +43,7 @@ protected function feedParserWithNodes(Parser $parser): void
4243
while (($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS) !== $aheadType) {
4344
if (($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA) === $aheadType) {
4445
$parser->match($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA);
46+
// @phpstan-ignore-next-line
4547
$this->nodes[] = $parser->{$this->commonNodeMapping}();
4648
}
4749

src/MartinGeorgiev/Utils/DataStructure.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ public static function transformPostgresTextArrayToPHPArray(string $postgresArra
4848
continue;
4949
}
5050

51-
if (!\is_string($text)) {
52-
$exceptionMessage = 'Unsupported data type encountered. Expected null, integer, float or string value. Instead it is "%s".';
53-
54-
throw new \InvalidArgumentException(\sprintf($exceptionMessage, \gettype($text)));
55-
}
56-
5751
$phpArray[$i] = \stripslashes(\str_replace('\"', '"', $text));
5852
}
5953

@@ -78,7 +72,13 @@ public static function transformPHPArrayToPostgresTextArray(array $phpArray): st
7872
throw new \InvalidArgumentException('Only single-dimensioned arrays are supported');
7973
}
8074

81-
$escapedText = \is_numeric($text) || \ctype_digit($text) ? $text : \sprintf('"%s"', \addcslashes($text, '"\\'));
75+
if (\is_numeric($text) || \ctype_digit($text)) {
76+
$escapedText = $text;
77+
} else {
78+
\assert(\is_string($text));
79+
$escapedText = \sprintf('"%s"', \addcslashes($text, '"\\'));
80+
}
81+
8282
$result[] = $escapedText;
8383
}
8484

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
abstract class TestCase extends BaseTestCase
1616
{
17+
/**
18+
* @var string
19+
*/
1720
protected const FIXTURES_DIRECTORY = __DIR__.'/../../../../../../fixtures/MartinGeorgiev/Doctrine/Entity';
1821

1922
private Configuration $configuration;
@@ -34,6 +37,7 @@ protected function setUp(): void
3437
private function setConfigurationCache(Configuration $configuration): void
3538
{
3639
$symfonyArrayAdapterClass = '\\'.ArrayAdapter::class;
40+
// @phpstan-ignore-next-line
3741
$useDbalV3 = \class_exists($symfonyArrayAdapterClass) && \method_exists($configuration, 'setMetadataCache') && \method_exists($configuration, 'setQueryCache');
3842
if ($useDbalV3) {
3943
// @phpstan-ignore-next-line
@@ -45,6 +49,7 @@ private function setConfigurationCache(Configuration $configuration): void
4549
}
4650

4751
$doctrineArrayCacheClass = '\Doctrine\Common\Cache\ArrayCache';
52+
// @phpstan-ignore-next-line
4853
$useDbalV2 = \class_exists($doctrineArrayCacheClass) && \method_exists($configuration, 'setMetadataCacheImpl') && \method_exists($configuration, 'setQueryCacheImpl');
4954
if ($useDbalV2) {
5055
// @phpstan-ignore-next-line

0 commit comments

Comments
 (0)