Skip to content

Commit 970c7ee

Browse files
authored
Upgrade to PHPStan 2.x (#785)
* Upgrade to PHPStan 2.x * fix * fix * Update RexSqlSetTableTypeSpecifyingExtension.php * fix * Update RexSqlInjectionRule.php * Update phpstan.dev.neon * Update RexCmd.php * Update RexSqlInjectionRule.php * Update RexStan.php * Update phpstan.dev.neon * fix * Update RexStan.php * Update composer.json
1 parent ef1b8b8 commit 970c7ee

File tree

455 files changed

+6288
-4313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

455 files changed

+6288
-4313
lines changed

composer.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
"php": ">=7.4",
44
"justinrainbow/json-schema": "^5.3",
55
"php-parallel-lint/php-parallel-lint": "1.4",
6-
"phpstan/phpstan": "1.12.12",
7-
"phpstan/phpstan-deprecation-rules": "1.2.1",
8-
"phpstan/phpstan-phpunit": "1.4.1",
9-
"phpstan/phpstan-strict-rules": "1.6.1",
10-
"phpstan/phpstan-symfony": "1.4.12",
11-
"spaze/phpstan-disallowed-calls": "2.16.1",
6+
"phpstan/phpstan": "2.0.3",
7+
"phpstan/phpstan-deprecation-rules": "2.0.1",
8+
"phpstan/phpstan-phpunit": "2.0.1",
9+
"phpstan/phpstan-strict-rules": "2.0.0",
10+
"phpstan/phpstan-symfony": "2.0.0",
11+
"spaze/phpstan-disallowed-calls": "4.0.1",
1212
"sqlftw/sqlftw": "0.1.16",
1313
"staabm/phpstan-baseline-analysis": "0.13",
14-
"staabm/phpstan-dba": "0.2.85",
14+
"staabm/phpstan-dba": "0.3",
1515
"staabm/phpstan-todo-by": "0.2",
16-
"symplify/phpstan-rules": "12.7.0",
17-
"tomasvotruba/cognitive-complexity": "0.2.3",
18-
"tomasvotruba/type-coverage": "1.0.0",
19-
"tomasvotruba/unused-public": "1.1.0"
16+
"symplify/phpstan-rules": "14.0.2",
17+
"tomasvotruba/cognitive-complexity": "1.0",
18+
"tomasvotruba/type-coverage": "2.0.0",
19+
"tomasvotruba/unused-public": "2.0.0",
20+
"rector/type-perfect": "2.0.0"
2021
},
2122
"autoload": {
2223
"classmap": [

composer.lock

+160-109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/code-complexity.neon

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
services:
2-
- Symplify\PHPStanRules\Rules\Explicit\NoMixedPropertyFetcherRule
3-
- Symplify\PHPStanRules\Rules\Explicit\NoMixedMethodCallerRule
1+
includes:
2+
- ../vendor/rector/type-perfect/config/extension.neon
3+
4+
parameters:
5+
type_perfect:
6+
no_mixed_property: true
7+
no_mixed_caller: true
8+
null_over_false: false
9+
narrow_param: false
10+
narrow_return: false

config/phpstan-dba.neon

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
services:
2+
-
3+
class: staabm\PHPStanDba\QueryReflection\DIContainerBridge
4+
25
-
36
class: staabm\PHPStanDba\Ast\PreviousConnectingVisitor
47
tags:

default-config.neon

-5
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,3 @@ services:
197197
class: rexstan\YOrmDatasetOptionalTableRule
198198
tags:
199199
- phpstan.rules.rule
200-
201-
-
202-
class: Symplify\PHPStanRules\Rules\CheckTypehintCallerTypeRule
203-
tags:
204-
- phpstan.rules.rule

lib/RexCmd.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function execCmd(string $cmd, &$stderrOutput, &$exitCode)
4040
$output = stream_get_contents($pipes[1]);
4141
fclose($pipes[1]);
4242

43-
$stderrOutput = stream_get_contents($pipes[2]);
43+
$stderrOutput = stream_get_contents($pipes[2]) ?: '';
4444
fclose($pipes[2]);
4545

4646
$status = proc_get_status($process);

lib/RexStan.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function runFromCli(&$exitCode, ?string $path, string $arguments,
3535

3636
$cmd .= ' 2>&1';
3737

38-
return RexCmd::execCmd($cmd, $errorOutput, $exitCode);
38+
return RexCmd::execCmd($cmd, $errorOutput, $exitCode); // @phpstan-ignore argument.type
3939
}
4040

4141
/**

lib/extension/RexSqlSelectTypeSpecifyingExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
5252
}
5353

5454
if ($inferedType !== null) {
55-
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), true);
55+
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), $scope)->setAlwaysOverwriteTypes();
5656
}
5757

5858
return new SpecifiedTypes();

lib/extension/RexSqlSetQueryTypeSpecifyingExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
5353
}
5454

5555
if ($inferedType !== null) {
56-
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), true);
56+
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), $scope)->setAlwaysOverwriteTypes();
5757
}
5858

5959
return new SpecifiedTypes();

lib/extension/RexSqlSetTableTypeSpecifyingExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
5252
}
5353

5454
if ($inferedType !== null) {
55-
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), true);
55+
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), $scope)->setAlwaysOverwriteTypes();
5656
}
5757

5858
return new SpecifiedTypes();

lib/reflection/RexSqlReflection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static function getResultTypeFromStatementType(Type $statementType): ?Typ
107107
return null;
108108
}
109109

110-
if (!$statementType instanceof GenericObjectType) {
110+
if (!$statementType instanceof GenericObjectType) { // @phpstan-ignore phpstanApi.instanceofType
111111
return null;
112112
}
113113

lib/rule/RexSqlInjectionRule.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ public function processNode(Node $methodCall, Scope $scope): array
118118
return [];
119119
}
120120

121-
private function findInsecureSqlExpr(Node\Expr $expr, Scope $scope, bool $resolveVariables = true): ?Node\Expr
121+
/**
122+
* @param Node\Expr|Node\InterpolatedStringPart $expr
123+
*/
124+
private function findInsecureSqlExpr($expr, Scope $scope, bool $resolveVariables = true): ?Node\Expr
122125
{
123126
if ($resolveVariables === true && $expr instanceof Node\Expr\Variable) {
124127
$finder = new ExpressionFinder();

lib/type/RexSqlObjectType.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace rexstan;
66

77
use PHPStan\TrinaryLogic;
8+
use PHPStan\Type\IsSuperTypeOfResult;
89
use PHPStan\Type\ObjectType;
910
use PHPStan\Type\Type;
1011
use rex_sql;
@@ -58,10 +59,10 @@ public function equals(Type $type): bool
5859
return parent::equals($type);
5960
}
6061

61-
public function isSuperTypeOf(Type $type): TrinaryLogic
62+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
6263
{
6364
if ($type instanceof self) {
64-
return TrinaryLogic::createFromBoolean(
65+
return IsSuperTypeOfResult::createFromBoolean(
6566
$this->getSelectExpression() === $type->getSelectExpression()
6667
&& $this->getTableName() === $type->getTableName()
6768
);

phpstan.dev.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
parameters:
2+
treatPhpDocTypesAsCertain: false
23
level: 8
34
paths:
45
- lib/
56
- pages/
67

78
ignoreErrors:
89
# error to be fixed in phpstan 2.0, see https://github.com/phpstan/phpstan-src/pull/1754
9-
- '#.*getValueType\(\) expects class\-string, string given\.$#'
1010
- '#^Cannot access offset ''running'' on array\{command\: string, pid\: int, running\: bool, signaled\: bool, stopped\: bool, exitcode\: int, termsig\: int, stopsig\: int\}\|false\.$#'
1111
# functions get polyfilled by redaxo core
1212
-

vendor/composer/InstalledVersions.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ private static function getInstalled()
322322
}
323323

324324
$installed = array();
325+
$copiedLocalDir = false;
325326

326327
if (self::$canGetVendors) {
327328
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
@@ -330,9 +331,11 @@ private static function getInstalled()
330331
} elseif (is_file($vendorDir.'/composer/installed.php')) {
331332
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
332333
$required = require $vendorDir.'/composer/installed.php';
333-
$installed[] = self::$installedByVendor[$vendorDir] = $required;
334-
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
335-
self::$installed = $installed[count($installed) - 1];
334+
self::$installedByVendor[$vendorDir] = $required;
335+
$installed[] = $required;
336+
if (strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
337+
self::$installed = $required;
338+
$copiedLocalDir = true;
336339
}
337340
}
338341
}
@@ -350,7 +353,7 @@ private static function getInstalled()
350353
}
351354
}
352355

353-
if (self::$installed !== array()) {
356+
if (self::$installed !== array() && !$copiedLocalDir) {
354357
$installed[] = self::$installed;
355358
}
356359

0 commit comments

Comments
 (0)