Skip to content

Commit 7dfcbf1

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents ef25c91 + d9311dd commit 7dfcbf1

File tree

7 files changed

+46
-0
lines changed

7 files changed

+46
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ lint:
118118
--exclude tests/PHPStan/Rules/Properties/data/property-hook-attributes-nodiscard.php \
119119
--exclude tests/PHPStan/Rules/Functions/data/arrow-function-typehints-nodiscard.php \
120120
--exclude tests/PHPStan/Rules/Functions/data/closure-typehints-nodiscard.php \
121+
--exclude tests/PHPStan/Reflection/data/ClassWithConstants.php \
121122
--exclude tests/PHPStan/Rules/Functions/data/typehints-nodiscard.php \
122123
--exclude tests/PHPStan/Rules/Methods/data/typehints-nodiscard.php \
123124
--exclude tests/PHPStan/Rules/Cast/data/deprecated-cast.php \

src/Reflection/ClassConstantReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function getValueExpr(): Expr;
2828

2929
public function isFinal(): bool;
3030

31+
public function isFinalByKeyword(): bool;
32+
3133
public function hasPhpDocType(): bool;
3234

3335
public function getPhpDocType(): ?Type;

src/Reflection/Dummy/DummyClassConstantReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function isFinal(): bool
3232
return false;
3333
}
3434

35+
public function isFinalByKeyword(): bool
36+
{
37+
return false;
38+
}
39+
3540
public function getFileName(): ?string
3641
{
3742
return null;

src/Reflection/RealClassClassConstantReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public function isFinal(): bool
121121
return $this->isFinal || $this->reflection->isFinal();
122122
}
123123

124+
public function isFinalByKeyword(): bool
125+
{
126+
return $this->reflection->isFinal();
127+
}
128+
124129
public function isDeprecated(): TrinaryLogic
125130
{
126131
return TrinaryLogic::createFromBoolean($this->isDeprecated || $this->reflection->isDeprecated());

src/Rules/RestrictedUsage/RewrittenDeclaringClassClassConstantReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function isFinal(): bool
2929
return $this->constantReflection->isFinal();
3030
}
3131

32+
public function isFinalByKeyword(): bool
33+
{
34+
return $this->constantReflection->isFinalByKeyword();
35+
}
36+
3237
public function hasPhpDocType(): bool
3338
{
3439
return $this->constantReflection->hasPhpDocType();

tests/PHPStan/Reflection/ClassReflectionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Attributes\IsAttribute2;
88
use Attributes\IsAttribute3;
99
use Attributes\IsNotAttribute;
10+
use ClassConstantReflectionTest\ClassWithConstants;
1011
use GenericInheritance\C;
1112
use HasTraitUse\Bar;
1213
use HasTraitUse\Baz;
@@ -191,6 +192,20 @@ public function testDeprecatedConstantFromAnotherFile(): void
191192
$this->assertTrue($constant->isDeprecated()->yes());
192193
}
193194

195+
#[RequiresPhp('>= 8.1')]
196+
public function testFinalConstant(): void
197+
{
198+
$reflectionProvider = self::createReflectionProvider();
199+
$reflection = $reflectionProvider->getClass(ClassWithConstants::class);
200+
$constant = $reflection->getConstant('FINAL_FROM_DOCBLOCK');
201+
$this->assertTrue($constant->isFinal());
202+
$this->assertFalse($constant->isFinalByKeyword());
203+
204+
$constant = $reflection->getConstant('NATIVE_FINAL');
205+
$this->assertTrue($constant->isFinal());
206+
$this->assertTrue($constant->isFinalByKeyword());
207+
}
208+
194209
/**
195210
* @param class-string $className
196211
* @param array<class-string, class-string> $expected
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace ClassConstantReflectionTest;
4+
5+
class ClassWithConstants
6+
{
7+
/**
8+
* @final
9+
*/
10+
public const FINAL_FROM_DOCBLOCK = 'final from docblock';
11+
12+
public final const NATIVE_FINAL = 'native final';
13+
}

0 commit comments

Comments
 (0)