Skip to content

Commit 4659277

Browse files
authored
More strict static analysis (#488)
1 parent 246281f commit 4659277

24 files changed

+126
-28
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpstan-dba-pdo-mysql.cache

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
"doctrine/dbal": "^3.2",
1616
"friendsofphp/php-cs-fixer": "3.4.0",
1717
"php-parallel-lint/php-parallel-lint": "^1.3",
18+
"phpstan/extension-installer": "^1.2",
1819
"phpstan/phpstan-php-parser": "^1.1",
1920
"phpstan/phpstan-phpunit": "^1.0",
2021
"phpstan/phpstan-strict-rules": "^1.1",
2122
"phpunit/phpunit": "^9",
23+
"tomasvotruba/unused-public": "^0.0.26",
2224
"vlucas/phpdotenv": "^5.4"
2325
},
2426
"conflicts": {
@@ -86,7 +88,8 @@
8688
"config": {
8789
"sort-packages": true,
8890
"allow-plugins": {
89-
"composer/package-versions-deprecated": true
91+
"composer/package-versions-deprecated": true,
92+
"phpstan/extension-installer": true
9093
}
9194
},
9295
"extra": {

phpstan-baseline.neon

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Instanceof between mysqli_result\<array\<string, int\|string\|null\>\> and mysqli_result will always evaluate to true\.$#'
5+
count: 1
6+
path: src/DbSchema/SchemaHasherMysql.php
7+
8+
-
9+
message: "#^Instanceof between mysqli_result\\<array\\<string, int\\<\\-128, 127\\>\\|string\\|null\\>\\> and mysqli_result will always evaluate to true\\.$#"
10+
count: 1
11+
path: src/DbSchema/SchemaHasherMysql.php
12+
13+
-
14+
message: "#^Strict comparison using \\!\\=\\= between null and PHPStan\\\\Type\\\\Type will always evaluate to true\\.$#"
15+
count: 1
16+
path: src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php
17+
18+
-
19+
message: "#^Strict comparison using \\=\\=\\= between 'dibi' and 'dibi' will always evaluate to true\\.$#"
20+
count: 1
21+
path: src/QueryReflection/DbaApi.php
22+
23+
-
24+
message: "#^Return type \\(array\\<int, array\\{name\\: string, table\\?\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoPgSqlQueryReflector\\:\\:simulateQuery\\(\\) should be covariant with return type \\(array\\<int, array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: 0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\|2147483648\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\BasePdoQueryReflector\\:\\:simulateQuery\\(\\)$#"
25+
count: 1
26+
path: src/QueryReflection/PdoPgSqlQueryReflector.php
27+
28+
-
29+
message: "#^Casting to \\*NEVER\\* something that's already \\*NEVER\\*\\.$#"
30+
count: 1
31+
path: src/QueryReflection/QueryReflection.php
32+
33+
-
34+
message: "#^Instanceof between PHPStan\\\\Type\\\\Constant\\\\ConstantIntegerType and PHPStan\\\\Type\\\\Constant\\\\ConstantIntegerType will always evaluate to true\\.$#"
35+
count: 1
36+
path: src/QueryReflection/QueryReflection.php
37+
38+
-
39+
message: "#^Strict comparison using \\=\\=\\= between null and null will always evaluate to true\\.$#"
40+
count: 1
41+
path: src/QueryReflection/QueryReflection.php
42+
43+
-
44+
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
45+
count: 2
46+
path: src/TypeMapping/MysqliTypeMapper.php
47+
48+
-
49+
message: "#^Only booleans are allowed in an if condition, int given\\.$#"
50+
count: 1
51+
path: src/TypeMapping/MysqliTypeMapper.php

phpstan.neon.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
includes:
22
- config/stubFiles.neon
33
- config/extensions.neon
4+
- phpstan-baseline.neon
45

56
parameters:
67
level: max
78

89
paths:
910
- src/
1011

12+
unused_public:
13+
methods: true
14+
properties: true
15+
constants: true
16+
1117
bootstrapFiles:
1218
- bootstrap.php
1319

src/Analyzer/QueryPlanAnalyzer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace staabm\PHPStanDba\Analyzer;
66

7+
/**
8+
* @api
9+
*/
710
final class QueryPlanAnalyzer
811
{
912
/**

src/Analyzer/QueryPlanAnalyzerMysql.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
final class QueryPlanAnalyzerMysql
1313
{
1414
/**
15+
* @api
16+
*
1517
* @deprecated use QueryPlanAnalyzer::DEFAULT_UNINDEXED_READS_THRESHOLD instead
1618
*/
1719
public const DEFAULT_UNINDEXED_READS_THRESHOLD = QueryPlanAnalyzer::DEFAULT_UNINDEXED_READS_THRESHOLD;
1820
/**
21+
* @api
22+
*
1923
* @deprecated use QueryPlanAnalyzer::TABLES_WITHOUT_DATA instead
2024
*/
2125
public const TABLES_WITHOUT_DATA = QueryPlanAnalyzer::TABLES_WITHOUT_DATA;
2226
/**
27+
* @api
28+
*
2329
* @deprecated use QueryPlanAnalyzer::DEFAULT_SMALL_TABLE_THRESHOLD instead
2430
*/
2531
public const DEFAULT_SMALL_TABLE_THRESHOLD = QueryPlanAnalyzer::DEFAULT_SMALL_TABLE_THRESHOLD;

src/Ast/ExpressionFinder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function __construct()
2727
}
2828

2929
/**
30+
* @api
31+
*
3032
* @param Variable|MethodCall $expr
3133
*
3234
* @deprecated use findAssignmentExpression() instead

src/Ast/PreviousConnectingVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class PreviousConnectingVisitor extends NodeVisitorAbstract
1414
public const ATTRIBUTE_PREVIOUS = 'dba-previous';
1515

1616
/**
17-
* @var Node[]
17+
* @var list<Node>
1818
*/
1919
private $stack = [];
2020

@@ -33,7 +33,7 @@ public function beforeTraverse(array $nodes)
3333

3434
public function enterNode(Node $node)
3535
{
36-
if (!empty($this->stack)) {
36+
if ([] !== $this->stack) {
3737
$node->setAttribute(self::ATTRIBUTE_PARENT, $this->stack[\count($this->stack) - 1]);
3838
}
3939

src/Error.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use staabm\PHPStanDba\QueryReflection\QuerySimulation;
88

99
/**
10+
* @api
11+
*
1012
* @phpstan-type ErrorCodes value-of<MysqliQueryReflector::MYSQL_ERROR_CODES>|value-of<BasePdoQueryReflector::PDO_ERROR_CODES>
1113
*/
1214
final class Error

0 commit comments

Comments
 (0)