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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ lint:
--exclude tests/PHPStan/Rules/Properties/data/property-hook-attributes-nodiscard.php \
--exclude tests/PHPStan/Rules/Functions/data/arrow-function-typehints-nodiscard.php \
--exclude tests/PHPStan/Rules/Functions/data/closure-typehints-nodiscard.php \
--exclude tests/PHPStan/Reflection/data/ClassWithConstants.php \
--exclude tests/PHPStan/Rules/Functions/data/typehints-nodiscard.php \
--exclude tests/PHPStan/Rules/Methods/data/typehints-nodiscard.php \
--exclude tests/PHPStan/Rules/Cast/data/deprecated-cast.php \
Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ClassConstantReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function getValueExpr(): Expr;

public function isFinal(): bool;

public function isFinalByKeyword(): bool;

public function hasPhpDocType(): bool;

public function getPhpDocType(): ?Type;
Expand Down
5 changes: 5 additions & 0 deletions src/Reflection/Dummy/DummyClassConstantReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function isFinal(): bool
return false;
}

public function isFinalByKeyword(): bool
{
return false;
}

public function getFileName(): ?string
{
return null;
Expand Down
5 changes: 5 additions & 0 deletions src/Reflection/RealClassClassConstantReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public function isFinal(): bool
return $this->isFinal || $this->reflection->isFinal();
}

public function isFinalByKeyword(): bool
{
return $this->reflection->isFinal();
}

public function isDeprecated(): TrinaryLogic
{
return TrinaryLogic::createFromBoolean($this->isDeprecated || $this->reflection->isDeprecated());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function isFinal(): bool
return $this->constantReflection->isFinal();
}

public function isFinalByKeyword(): bool
{
return $this->constantReflection->isFinalByKeyword();
}

public function hasPhpDocType(): bool
{
return $this->constantReflection->hasPhpDocType();
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Reflection/ClassReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Attributes\IsAttribute2;
use Attributes\IsAttribute3;
use Attributes\IsNotAttribute;
use ClassConstantReflectionTest\ClassWithConstants;
use GenericInheritance\C;
use HasTraitUse\Bar;
use HasTraitUse\Baz;
Expand Down Expand Up @@ -191,6 +192,20 @@ public function testDeprecatedConstantFromAnotherFile(): void
$this->assertTrue($constant->isDeprecated()->yes());
}

#[RequiresPhp('>= 8.1')]
public function testFinalConstant(): void
{
$reflectionProvider = self::createReflectionProvider();
$reflection = $reflectionProvider->getClass(ClassWithConstants::class);
$constant = $reflection->getConstant('FINAL_FROM_DOCBLOCK');
$this->assertTrue($constant->isFinal());
$this->assertFalse($constant->isFinalByKeyword());

$constant = $reflection->getConstant('NATIVE_FINAL');
$this->assertTrue($constant->isFinal());
$this->assertTrue($constant->isFinalByKeyword());
}

/**
* @param class-string $className
* @param array<class-string, class-string> $expected
Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Reflection/data/ClassWithConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace ClassConstantReflectionTest;

class ClassWithConstants
{
/**
* @final
*/
public const FINAL_FROM_DOCBLOCK = 'final from docblock';

public final const NATIVE_FINAL = 'native final';
}
Loading