Skip to content

Commit

Permalink
Merge pull request #3932 from morozov/phpstan-stricter
Browse files Browse the repository at this point in the history
Enable PHPStan strict rules
  • Loading branch information
morozov authored Apr 11, 2020
2 parents 66f0577 + b8066db commit 14f5f15
Show file tree
Hide file tree
Showing 167 changed files with 1,132 additions and 929 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"require-dev": {
"doctrine/coding-standard": "^6.0",
"jetbrains/phpstorm-stubs": "^2019.1",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^0.12.18",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.0",
"symfony/console": "^2.0.5|^3.0|^4.0|^5.0"
},
Expand Down
70 changes: 68 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
- %currentWorkingDirectory%/src
autoload_files:
- %currentWorkingDirectory%/tests/phpstan-polyfill.php
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
Expand Down Expand Up @@ -72,3 +73,48 @@ parameters:
-
message: '~^Cannot cast array<string>\|bool\|string\|null to int\.$~'
path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php

# https://github.com/phpstan/phpstan/issues/3134
-
message: '~^Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with Doctrine\\DBAL\\Types\\Type and Doctrine\\DBAL\\Types\\Type will always evaluate to true\.$~'
path: %currentWorkingDirectory%/tests/Types/TypeRegistryTest.php

# https://github.com/phpstan/phpstan-strict-rules/issues/103
-
message: '~^Construct empty\(\) is not allowed. Use more strict comparison\.~'
paths:
- %currentWorkingDirectory%/src/Driver/*/*Connection.php
- %currentWorkingDirectory%/src/Driver/*/Driver.php
- %currentWorkingDirectory%/src/Driver/AbstractOracleDriver/EasyConnectString.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php

# In some namespaces, we use array<string,mixed>, some elements of which are actually boolean
-
message: '~^Only booleans are allowed in .*, mixed given~'
paths:
- %currentWorkingDirectory%/src/Driver/*/Driver.php
- %currentWorkingDirectory%/src/Platforms/*Platform.php
- %currentWorkingDirectory%/src/Query/QueryBuilder.php
- %currentWorkingDirectory%/src/Schema/*SchemaManager.php

# FetchMode::CUSTOM_OBJECT requires variable property access
-
message: '~^Variable property access on object\.~'
paths:
- %currentWorkingDirectory%/src/Driver/*/*Statement.php

# Some APIs use variable method calls internally
-
message: '~^Variable method call on .*~'
paths:
- %currentWorkingDirectory%/src/Schema/AbstractSchemaManager.php
- %currentWorkingDirectory%/src/Schema/Column.php

# https://github.com/phpstan/phpstan/issues/3146
-
message: '~^Only numeric types are allowed in -, int<1, max>\|false given on the left side\.~'
paths:
- %currentWorkingDirectory%/src/Platforms/SQLServer2012Platform.php
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
4 changes: 2 additions & 2 deletions src/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
public function __construct(array $data)
{
$this->data = $data;
if (! count($data)) {
if (count($data) === 0) {
return;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public function fetch($fetchMode = null, ...$args)
}

$row = $this->data[$this->num++];
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
$fetchMode = $fetchMode ?? $this->defaultFetchMode;

if ($fetchMode === FetchMode::ASSOCIATIVE) {
return $row;
Expand Down
6 changes: 3 additions & 3 deletions src/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function closeCursor()
}

$data = $this->resultCache->fetch($this->cacheKey);
if (! $data) {
if ($data === false) {
$data = [];
}
$data[$this->realKey] = $this->data;
Expand Down Expand Up @@ -132,10 +132,10 @@ public function fetch($fetchMode = null, ...$args)

$row = $this->statement->fetch(FetchMode::ASSOCIATIVE);

if ($row) {
if ($row !== false) {
$this->data[] = $row;

$fetchMode = $fetchMode ?: $this->defaultFetchMode;
$fetchMode = $fetchMode ?? $this->defaultFetchMode;

if ($fetchMode === FetchMode::ASSOCIATIVE) {
return $row;
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public function setResultCacheImpl(Cache $cacheImpl)
*
* @deprecated Use Configuration::setSchemaAssetsFilter() instead
*
* @param string $filterExpression
* @param string|null $filterExpression
*
* @return void
*/
public function setFilterSchemaAssetsExpression($filterExpression)
{
$this->_attributes['filterSchemaAssetsExpression'] = $filterExpression;
if ($filterExpression) {
if ($filterExpression !== null) {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression);
} else {
$this->_attributes['filterSchemaAssetsExpressionCallable'] = null;
Expand Down
Loading

0 comments on commit 14f5f15

Please sign in to comment.