Skip to content

Commit 70ad4ae

Browse files
authored
Merge pull request #736 from lacatoire/feat/typed-constants-support-6x
Add support for PHP 8.3 typed class constants
2 parents 5e5db15 + 5d8c68c commit 70ad4ae

21 files changed

+333
-113
lines changed

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- name: "Dependabot metadata"
1515
id: "metadata"
16-
uses: "dependabot/fetch-metadata@v2.4.0"
16+
uses: "dependabot/fetch-metadata@v2.5.0"
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919
- name: "Enable auto-merge for Dependabot PRs"

.github/workflows/documentation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: "Deploy"
2121
if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/6.x' }}"
22-
uses: "actions/upload-artifact@v5"
22+
uses: "actions/upload-artifact@v7"
2323
with:
2424
name: "documentation"
2525
path: "build/docs"

composer.lock

Lines changed: 55 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,5 @@
225225
<ClassMustBeFinal>
226226
<code><![CDATA[NamespaceNodeToContext]]></code>
227227
</ClassMustBeFinal>
228-
<MixedArgumentTypeCoercion>
229-
<code><![CDATA[$this->aliasesToFullyQualifiedNames($namespace)]]></code>
230-
</MixedArgumentTypeCoercion>
231228
</file>
232229
</files>

src/phpDocumentor/Reflection/Php/Constant.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use phpDocumentor\Reflection\Fqsen;
2020
use phpDocumentor\Reflection\Location;
2121
use phpDocumentor\Reflection\Metadata\MetaDataContainer as MetaDataContainerInterface;
22+
use phpDocumentor\Reflection\Type;
2223

2324
use function is_string;
2425
use function trigger_error;
@@ -52,6 +53,7 @@ public function __construct(
5253
Location|null $endLocation = null,
5354
Visibility|null $visibility = null,
5455
private readonly bool $final = false,
56+
private readonly Type|null $type = null,
5557
) {
5658
$this->location = $location ?: new Location(-1);
5759
$this->endLocation = $endLocation ?: new Location(-1);
@@ -135,4 +137,9 @@ public function isFinal(): bool
135137
{
136138
return $this->final;
137139
}
140+
141+
public function getType(): Type|null
142+
{
143+
return $this->type;
144+
}
138145
}

src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string
8686
{
8787
$renderedName = parent::pObjectProperty($node->name);
8888

89-
if ($node->class instanceof Name) {
89+
if ($node->class instanceof Name\FullyQualified) {
90+
$className = parent::pName_FullyQualified($node->class);
91+
$className = $this->typeResolver->resolve($className, $this->context);
92+
} elseif ($node->class instanceof Name) {
9093
$className = parent::pName($node->class);
9194
$className = $this->typeResolver->resolve($className, $this->context);
9295
} else {

src/phpDocumentor/Reflection/Php/Factory/ClassConstant.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected function doCreate(
9393
new Location($const->getEndLine()),
9494
$this->buildVisibility($const),
9595
$const->isFinal(),
96+
(new Type())->fromPhpParser($const->getType(), $context->getTypeContext()),
9697
);
9798

9899
foreach ($this->reducers as $reducer) {

0 commit comments

Comments
 (0)