Skip to content

Commit

Permalink
Enable more PHPStan's extra strictness (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Dec 12, 2023
1 parent 6ff99cc commit deaf0c6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -16,6 +16,8 @@ parameters:
tmpDir: cache/phpstan/
checkMissingCallableSignature: true
checkUninitializedProperties: true
checkBenevolentUnionTypes: true
checkImplicitMixed: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
exceptions:
check:
Expand All @@ -34,6 +36,8 @@ parameters:
PHPStan\Rules\Rule: Rule
PhpParser\NodeVisitor: Visitor
ShipMonk\PHPStan\RuleTestCase: RuleTest
forbidAssignmentNotMatchingVarDoc:
enabled: false # native check is better now; this rule will be dropped / reworked in 3.0

ignoreErrors:
-
Expand Down
8 changes: 4 additions & 4 deletions src/Rule/ForbidCheckedExceptionInCallableRule.php
Expand Up @@ -67,14 +67,14 @@ public function __construct(
array $allowedCheckedExceptionCallables
)
{
/** @var array<string, int|list<int>> $callablesWithAllowedCheckedExceptions */
$callablesWithAllowedCheckedExceptions = array_merge_recursive($immediatelyCalledCallables, $allowedCheckedExceptionCallables);

$this->callablesAllowingCheckedExceptions = array_map(
function ($argumentIndexes): array {
return $this->normalizeArgumentIndexes($argumentIndexes);
},
array_merge_recursive(
$immediatelyCalledCallables,
$allowedCheckedExceptionCallables,
),
$callablesWithAllowedCheckedExceptions,
);
$this->exceptionTypeResolver = $exceptionTypeResolver;
$this->reflectionProvider = $reflectionProvider;
Expand Down
10 changes: 5 additions & 5 deletions src/Rule/ForbidUnusedMatchResultRule.php
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\VerbosityLevel;
use ShipMonk\PHPStan\Visitor\UnusedMatchVisitor;
Expand All @@ -35,11 +36,10 @@ public function processNode(Node $node, Scope $scope): array
$returnedTypes = [];

foreach ($node->arms as $arm) {
if (method_exists($scope, 'getKeepVoidType')) { // Needed since https://github.com/phpstan/phpstan/releases/tag/1.10.49
$armType = $scope->getKeepVoidType($arm->body);
} else {
$armType = $scope->getType($arm->body);
}
/** @var Type $armType */
$armType = method_exists($scope, 'getKeepVoidType') // Needed since https://github.com/phpstan/phpstan/releases/tag/1.10.49, can be dropped once we bump PHPStan version gte that
? $scope->getKeepVoidType($arm->body)
: $scope->getType($arm->body);

if (!$armType->isVoid()->yes() && !$armType instanceof NeverType && !$arm->body instanceof Assign) {
$returnedTypes[] = $armType;
Expand Down
1 change: 1 addition & 0 deletions src/Visitor/ImmediatelyCalledCallableVisitor.php
Expand Up @@ -52,6 +52,7 @@ public function __construct(
array $allowedCheckedExceptionCallables = []
)
{
/** @var array<string, int|list<int>> $callablesWithAllowedCheckedExceptions */
$callablesWithAllowedCheckedExceptions = array_merge_recursive($immediatelyCalledCallables, $allowedCheckedExceptionCallables);

foreach ($callablesWithAllowedCheckedExceptions as $call => $arguments) {
Expand Down
1 change: 1 addition & 0 deletions tests/RuleTestCase.php
Expand Up @@ -40,6 +40,7 @@ private function parseExpectedErrors(string $file): array

foreach ($fileDataLines as $line => $row) {
$matches = [];
/** @var array{0: list<string>, 1: list<string>} $matches */
$matched = preg_match_all('#// error:(.+)#', $row, $matches);

if ($matched === false) {
Expand Down

0 comments on commit deaf0c6

Please sign in to comment.