Skip to content

Commit c684505

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.0.x
2 parents 65ddbcb + 09f7c00 commit c684505

File tree

8 files changed

+43
-3
lines changed

8 files changed

+43
-3
lines changed

resources/functionMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,7 @@
29322932
'ffmpeg_movie::hasAudio' => ['bool'],
29332933
'ffmpeg_movie::hasVideo' => ['bool'],
29342934
'fgetc' => ['string|false', 'fp'=>'resource'],
2935-
'fgetcsv' => ['list<string>|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
2935+
'fgetcsv' => ['list<string>|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
29362936
'fgets' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int'],
29372937
'fgetss' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int', 'allowable_tags='=>'string'],
29382938
'file' => ['list<string>|false', 'filename'=>'string', 'flags='=>'int-mask<FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES|FILE_NO_DEFAULT_CONTEXT>', 'context='=>'resource'],

src/Reflection/ClassReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ public function getConstant(string $name): ClassConstantReflection
10701070
$deprecatedDescription = $resolvedPhpDoc->getDeprecatedTag() !== null ? $resolvedPhpDoc->getDeprecatedTag()->getMessage() : null;
10711071
$isDeprecated = $resolvedPhpDoc->isDeprecated();
10721072
$isInternal = $resolvedPhpDoc->isInternal();
1073+
$isFinal = $resolvedPhpDoc->isFinal();
10731074
$varTags = $resolvedPhpDoc->getVarTags();
10741075
if (isset($varTags[0]) && count($varTags) === 1) {
10751076
$phpDocType = $varTags[0]->getType();
@@ -1091,6 +1092,7 @@ public function getConstant(string $name): ClassConstantReflection
10911092
$deprecatedDescription,
10921093
$isDeprecated,
10931094
$isInternal,
1095+
$isFinal,
10941096
);
10951097
}
10961098
return $this->constants[$name];

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,7 @@ function (Type $type, callable $traverse): Type {
19831983
$constantReflection = $constantClassReflection->getConstant($constantName);
19841984
if (
19851985
!$constantClassReflection->isFinal()
1986+
&& !$constantReflection->isFinal()
19861987
&& !$constantReflection->hasPhpDocType()
19871988
&& !$constantReflection->hasNativeType()
19881989
) {

src/Reflection/RealClassClassConstantReflection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct(
2222
private ?string $deprecatedDescription,
2323
private bool $isDeprecated,
2424
private bool $isInternal,
25+
private bool $isFinal,
2526
)
2627
{
2728
}
@@ -105,7 +106,7 @@ public function isPublic(): bool
105106

106107
public function isFinal(): bool
107108
{
108-
return $this->reflection->isFinal();
109+
return $this->isFinal || $this->reflection->isFinal();
109110
}
110111

111112
public function isDeprecated(): TrinaryLogic

src/Type/ArrayType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PHPStan\Type\Constant\ConstantIntegerType;
2121
use PHPStan\Type\Constant\ConstantStringType;
2222
use PHPStan\Type\Generic\TemplateMixedType;
23+
use PHPStan\Type\Generic\TemplateStrictMixedType;
2324
use PHPStan\Type\Generic\TemplateTypeMap;
2425
use PHPStan\Type\Generic\TemplateTypeVariance;
2526
use PHPStan\Type\Traits\ArrayTypeTrait;
@@ -51,6 +52,10 @@ public function __construct(Type $keyType, private Type $itemType)
5152
if ($keyType->describe(VerbosityLevel::value()) === '(int|string)') {
5253
$keyType = new MixedType();
5354
}
55+
if ($keyType instanceof StrictMixedType && !$keyType instanceof TemplateStrictMixedType) {
56+
$keyType = new UnionType([new StringType(), new IntegerType()]);
57+
}
58+
5459
$this->keyType = $keyType;
5560
}
5661

tests/PHPStan/Analyser/nsrt/class-constant-types.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Foo
1515
/** @var string */
1616
private const PRIVATE_TYPE = 'foo';
1717

18+
/** @final */
19+
const FINAL_TYPE = 'zoo';
20+
1821
public function doFoo()
1922
{
2023
assertType('1', self::NO_TYPE);
@@ -28,6 +31,10 @@ public function doFoo()
2831
assertType('\'foo\'', self::PRIVATE_TYPE);
2932
assertType('string', static::PRIVATE_TYPE);
3033
assertType('string', $this::PRIVATE_TYPE);
34+
35+
assertType('\'zoo\'', self::FINAL_TYPE);
36+
assertType('\'zoo\'', static::FINAL_TYPE);
37+
assertType('\'zoo\'', $this::FINAL_TYPE);
3138
}
3239

3340
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class CallToFunctionParametersRuleTest extends RuleTestCase
2121

2222
private bool $checkExplicitMixed = false;
2323

24+
private bool $checkImplicitMixed = false;
25+
2426
protected function getRule(): Rule
2527
{
2628
$broker = $this->createReflectionProvider();
2729
return new CallToFunctionParametersRule(
2830
$broker,
29-
new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, $this->checkExplicitMixed, false, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true),
31+
new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, $this->checkExplicitMixed, $this->checkImplicitMixed, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(), new PropertyReflectionFinder(), true, true, true, true),
3032
);
3133
}
3234

@@ -1910,4 +1912,11 @@ public function testBug11759(): void
19101912
$this->analyse([__DIR__ . '/data/bug-11759.php'], []);
19111913
}
19121914

1915+
public function testBug12051(): void
1916+
{
1917+
$this->checkExplicitMixed = true;
1918+
$this->checkImplicitMixed = true;
1919+
$this->analyse([__DIR__ . '/data/bug-12051.php'], []);
1920+
}
1921+
19131922
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug12051;
4+
5+
/** @param array<int|string, mixed> $a */
6+
function foo($a): void {
7+
print "ok\n";
8+
}
9+
10+
/**
11+
* @param array<mixed> $a
12+
*/
13+
function bar($a): void {
14+
foo($a);
15+
}

0 commit comments

Comments
 (0)