Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Analyser/Ignore/IgnoredErrorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,18 @@ public function initialize(): IgnoredErrorHelperResult
continue;
}

$reportUnmatched = (bool) ($uniquedExpandedIgnoreErrors[$key]['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors);
if (!$reportUnmatched) {
$reportUnmatched = $ignoreError['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this change relate to the rest?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous expression

($uniquedExpandedIgnoreErrors[$key]['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors) || ($ignoreError['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors)

errored with

Only booleans are allowed in ||, mixed given on the right side.


$uniquedExpandedIgnoreErrors[$key] = [
'message' => $ignoreError['message'] ?? null,
'rawMessage' => $ignoreError['rawMessage'] ?? null,
'path' => $ignoreError['path'],
'identifier' => $ignoreError['identifier'] ?? null,
'count' => ($uniquedExpandedIgnoreErrors[$key]['count'] ?? 1) + ($ignoreError['count'] ?? 1),
'reportUnmatched' => ($uniquedExpandedIgnoreErrors[$key]['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors) || ($ignoreError['reportUnmatched'] ?? $this->reportUnmatchedIgnoredErrors),
'reportUnmatched' => $reportUnmatched,
];
}

Expand Down
19 changes: 13 additions & 6 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,10 @@
return $offsetAccessibleType;
}

if (!$offsetAccessibleType->isArray()->yes() && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes()) {
if (
!$offsetAccessibleType->isArray()->yes()

Check warning on line 1861 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ } if ( - !$offsetAccessibleType->isArray()->yes() + $offsetAccessibleType->isArray()->no() && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes() ) { return $this->getType(

Check warning on line 1861 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ } if ( - !$offsetAccessibleType->isArray()->yes() + $offsetAccessibleType->isArray()->no() && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes() ) { return $this->getType(
&& (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes()

Check warning on line 1862 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( !$offsetAccessibleType->isArray()->yes() - && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes() + && !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->no() ) { return $this->getType( new MethodCall(

Check warning on line 1862 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ if ( !$offsetAccessibleType->isArray()->yes() - && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes() + && $offsetAccessibleType->isSuperTypeOf(new ObjectType(ArrayAccess::class))->yes() ) { return $this->getType( new MethodCall(

Check warning on line 1862 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( !$offsetAccessibleType->isArray()->yes() - && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes() + && !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->no() ) { return $this->getType( new MethodCall(

Check warning on line 1862 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ if ( !$offsetAccessibleType->isArray()->yes() - && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes() + && $offsetAccessibleType->isSuperTypeOf(new ObjectType(ArrayAccess::class))->yes() ) { return $this->getType( new MethodCall(
) {
return $this->getType(
new MethodCall(
$arrayDimFetch->var,
Expand Down Expand Up @@ -3368,11 +3371,15 @@
$dimType = $scope->getType($expr->dim)->toArrayKey();
if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) {
$exprVarType = $scope->getType($expr->var);
if (!$exprVarType instanceof MixedType && !$exprVarType->isArray()->no()) {
if ($dimType->isInteger()->yes()) {
$varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::intOffsetAccessibleType());
} else {
$varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::generalOffsetAccessibleType());
$isArray = $exprVarType->isArray();
if (!$exprVarType instanceof MixedType && !$isArray->no()) {

Check warning on line 3375 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) { $exprVarType = $scope->getType($expr->var); $isArray = $exprVarType->isArray(); - if (!$exprVarType instanceof MixedType && !$isArray->no()) { + if (!$exprVarType instanceof MixedType && $isArray->yes()) { $varType = $exprVarType; if (!$isArray->yes()) { if ($dimType->isInteger()->yes()) {

Check warning on line 3375 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) { $exprVarType = $scope->getType($expr->var); $isArray = $exprVarType->isArray(); - if (!$exprVarType instanceof MixedType && !$isArray->no()) { + if (!$exprVarType instanceof MixedType && $isArray->yes()) { $varType = $exprVarType; if (!$isArray->yes()) { if ($dimType->isInteger()->yes()) {
$varType = $exprVarType;
if (!$isArray->yes()) {
if ($dimType->isInteger()->yes()) {

Check warning on line 3378 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if (!$exprVarType instanceof MixedType && !$isArray->no()) { $varType = $exprVarType; if (!$isArray->yes()) { - if ($dimType->isInteger()->yes()) { + if (!$dimType->isInteger()->no()) { $varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::intOffsetAccessibleType()); } else { $varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::generalOffsetAccessibleType());

Check warning on line 3378 in src/Analyser/MutatingScope.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if (!$exprVarType instanceof MixedType && !$isArray->no()) { $varType = $exprVarType; if (!$isArray->yes()) { - if ($dimType->isInteger()->yes()) { + if (!$dimType->isInteger()->no()) { $varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::intOffsetAccessibleType()); } else { $varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::generalOffsetAccessibleType());
$varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::intOffsetAccessibleType());
} else {
$varType = TypeCombinator::intersect($exprVarType, StaticTypeFactory::generalOffsetAccessibleType());
}
}

if ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType) {
Expand Down
23 changes: 23 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11518-types-php7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php // lint < 8.0

namespace Bug11518TypesPhp7;

use function PHPStan\Testing\assertType;

/**
* @param mixed[] $a
* @return array{thing: mixed}
* */
function blah(array $a): array
{
if (!array_key_exists('thing', $a)) {
$a['thing'] = 'bla';
assertType('non-empty-array<mixed>&hasOffsetValue(\'thing\', \'bla\')', $a);
} else {
assertType('non-empty-array&hasOffset(\'thing\')', $a);
}

assertType('non-empty-array&hasOffsetValue(\'thing\', mixed)', $a);

return $a;
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-11518-types.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // lint >= 8.0

namespace Bug11518Types;

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-2911.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ private function getResultSettings(array $settings): array
function foo(array $array): void {
$array['bar'] = 'string';

assertType("non-empty-array&hasOffsetValue('bar', 'string')", $array);
assertType("non-empty-array<mixed>&hasOffsetValue('bar', 'string')", $array);
}
}
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/nsrt/composer-array-bug.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ public function doFoo(): void
}
}

assertType("non-empty-array&hasOffsetValue('authors', mixed)", $this->config);
assertType("non-empty-array<mixed>&hasOffsetValue('authors', mixed)", $this->config);
assertType("mixed", $this->config['authors']);

if (empty($this->config['authors'])) {
unset($this->config['authors']);
assertType("array<mixed~'authors', mixed>", $this->config);
} else {
assertType("non-empty-array&hasOffsetValue('authors', mixed~(0|0.0|''|'0'|array{}|false|null))", $this->config);
assertType("non-empty-array<mixed>&hasOffsetValue('authors', mixed~(0|0.0|''|'0'|array{}|false|null))", $this->config);
}

assertType("array", $this->config);
assertType("array<mixed>", $this->config);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/nsrt/superglobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function canBeOverwritten(): void
public function canBePartlyOverwritten(): void
{
$GLOBALS['foo'] = 'foo';
assertType("non-empty-array&hasOffsetValue('foo', 'foo')", $GLOBALS);
assertType("non-empty-array<mixed>&hasOffsetValue('foo', 'foo')", $GLOBALS);
assertNativeType("non-empty-array<mixed>&hasOffsetValue('foo', 'foo')", $GLOBALS);
}

public function canBeNarrowed(): void
{
if (isset($GLOBALS['foo'])) {
assertType("non-empty-array&hasOffsetValue('foo', mixed~null)", $GLOBALS);
assertType("non-empty-array<mixed>&hasOffsetValue('foo', mixed~null)", $GLOBALS);
assertNativeType("non-empty-array<mixed>&hasOffset('foo')", $GLOBALS); // https://github.com/phpstan/phpstan/issues/8395
} else {
assertType('array<mixed>', $GLOBALS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ public function testBug2911(): void
{
$this->analyse([__DIR__ . '/data/bug-2911.php'], [
[
'Parameter #1 $array of function Bug2911\bar expects array{bar: string}, non-empty-array given.',
'Parameter #1 $array of function Bug2911\bar expects array{bar: string}, non-empty-array<mixed> given.',
23,
],
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Functions/data/bug-7156.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function foobar2(mixed $data): void
throw new \RuntimeException();
}

assertType("non-empty-array&hasOffsetValue('value', string)", $data);
assertType("non-empty-array<mixed, mixed>&hasOffsetValue('value', string)", $data);

foo($data);
}
Loading