Skip to content
8 changes: 1 addition & 7 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1473,12 +1473,6 @@ parameters:
count: 1
path: src/Type/ObjectShapeType.php

-
rawMessage: 'Doing instanceof PHPStan\Type\Enum\EnumCaseObjectType is error-prone and deprecated. Use Type::getEnumCases() instead.'
identifier: phpstanApi.instanceofType
count: 1
path: src/Type/ObjectType.php

-
rawMessage: Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.
identifier: phpstanApi.instanceofType
Expand All @@ -1488,7 +1482,7 @@ parameters:
-
rawMessage: 'Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.'
identifier: phpstanApi.instanceofType
count: 3
count: 2
path: src/Type/ObjectType.php

-
Expand Down
6 changes: 1 addition & 5 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult

public function equals(Type $type): bool
{
if (!$type instanceof self) {
return false;
}

if ($type instanceof EnumCaseObjectType) {
if (get_class($type) !== static::class) {
return false;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14429.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14429Nsrt;

use function PHPStan\Testing\assertType;
use function PHPStan\Testing\assertNativeType;

/**
* @param \ArrayObject<string, int> $intKeyMap
* @param \ArrayObject<string, string> $stringMap
*/
function testBoth(\ArrayObject $intKeyMap, \ArrayObject $stringMap): void
{
foreach ($intKeyMap as $intKeyMapValue) {
assertType("int", $intKeyMapValue);
assertNativeType("mixed", $intKeyMapValue);
}
foreach ($stringMap as $stringMapValue) {
assertType("string", $stringMapValue);
assertNativeType("mixed", $stringMapValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1207,4 +1207,11 @@ public function testBug13799(): void
]);
}

#[RequiresPhp('>= 8.0')]
public function testBug14429(): void
{
$this->treatPhpDocTypesAsCertain = false;
$this->analyse([__DIR__ . '/data/bug-14429.php'], []);
}

}
29 changes: 29 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-14429.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14429;

function throw_if(bool $condition, string $message): void
{
if ($condition) { throw new \Exception($message); }
}

class Foo
{
/**
* @param \ArrayObject<string, string> $stringMap
* @param \ArrayObject<string, int> $intKeyMap
*/
public function __construct(
public \ArrayObject $stringMap,
public \ArrayObject $intKeyMap,
) {
foreach ($stringMap as $stringMapValue) {
throw_if(!is_string($stringMapValue), 'stringMap value must be string');
}
foreach ($intKeyMap as $intKeyMapKey => $intKeyMapValue) {
throw_if(!is_int($intKeyMapValue), 'intKeyMap value must be int');
}
}
}
Loading