Skip to content

Commit 0c9fccc

Browse files
author
roadiz-ci
committed
Merge branch hotfix/2.7.37
1 parent 53baeb0 commit 0c9fccc

12 files changed

Lines changed: 48 additions & 31 deletions

.github/workflows/run-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Static analysis and code style
33
on:
44
push:
55
branches:
6-
- main
76
- develop
87
- 'release/**'
98
- 'hotfix/**'
@@ -20,7 +19,7 @@ jobs:
2019
runs-on: ubuntu-latest
2120
strategy:
2221
matrix:
23-
php-version: ['8.2', '8.3']
22+
php-version: ['8.3', '8.4', '8.5']
2423
steps:
2524
- uses: shivammathur/setup-php@v2
2625
with:

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2024 Ambroise Maupate
3+
Copyright © 2025 Ambroise Maupate
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"description": "Roadiz sub-package which generates Typescript interfaces skeleton based on your schema",
44
"type": "library",
55
"require": {
6-
"roadiz/nodetype-contracts": "^2.0.0",
7-
"symfony/http-foundation": "6.4.*"
6+
"roadiz/nodetype-contracts": "^3.1.1",
7+
"symfony/http-foundation": "7.4.*"
88
},
99
"require-dev": {
10-
"phpstan/phpstan": "^1.5.3",
10+
"phpstan/phpstan": "^2.1.36",
1111
"phpstan/phpdoc-parser": "<2"
1212
},
1313
"license": "MIT",
@@ -26,8 +26,8 @@
2626
},
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "2.5.x-dev",
30-
"dev-develop": "2.6.x-dev"
29+
"dev-master": "2.7.x-dev",
30+
"dev-develop": "2.8.x-dev"
3131
}
3232
}
3333
}

src/DeclarationGeneratorFactory.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace RZ\Roadiz\Typescript\Declaration;
66

7+
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
78
use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface;
89
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface;
910
use RZ\Roadiz\Typescript\Declaration\Generators\AbstractFieldGenerator;
@@ -17,8 +18,10 @@
1718

1819
final readonly class DeclarationGeneratorFactory
1920
{
20-
public function __construct(private ParameterBag $nodeTypesBag)
21-
{
21+
public function __construct(
22+
private ParameterBag $nodeTypesBag,
23+
private NodeTypeClassLocatorInterface $nodeTypeClassLocator,
24+
) {
2225
}
2326

2427
public function getNodeTypesBag(): ParameterBag
@@ -35,15 +38,16 @@ public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerato
3538
{
3639
return new NodeTypeGenerator(
3740
$nodeType,
38-
$this
41+
$this,
42+
$this->nodeTypeClassLocator
3943
);
4044
}
4145

4246
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
4347
{
4448
return match (true) {
4549
$field->isDocuments() => new DocumentsFieldGenerator($field, $this->nodeTypesBag),
46-
$field->isNodes() => new NodeReferencesFieldGenerator($field, $this->nodeTypesBag),
50+
$field->isNodes() => new NodeReferencesFieldGenerator($this->nodeTypeClassLocator, $field, $this->nodeTypesBag),
4751
$field->isChildrenNodes() => new ChildrenNodeFieldGenerator($field, $this->nodeTypesBag),
4852
$field->isMultiple(), $field->isEnum() => new EnumFieldGenerator($field, $this->nodeTypesBag),
4953
default => new ScalarFieldGenerator($field, $this->nodeTypesBag),

src/Generators/AbstractFieldGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ protected function getIntroductionLines(): array
5959

6060
public function getIntroduction(): string
6161
{
62-
return implode(PHP_EOL, array_map(function (string $line) {
63-
return static::INDENTATION_MARK.'// '.$line;
64-
}, $this->getIntroductionLines()));
62+
return implode(PHP_EOL, array_map(fn (string $line) => static::INDENTATION_MARK.'// '.$line, $this->getIntroductionLines()));
6563
}
6664
}

src/Generators/ChildrenNodeFieldGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
final class ChildrenNodeFieldGenerator extends AbstractFieldGenerator
88
{
9+
#[\Override]
910
public function getContents(): string
1011
{
1112
return implode(PHP_EOL, [
1213
$this->getIntroduction(),
1314
]);
1415
}
1516

17+
#[\Override]
1618
protected function getIntroductionLines(): array
1719
{
1820
$lines = [
@@ -25,6 +27,7 @@ protected function getIntroductionLines(): array
2527
return $lines;
2628
}
2729

30+
#[\Override]
2831
protected function getType(): string
2932
{
3033
return '';

src/Generators/DeclarationGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace RZ\Roadiz\Typescript\Declaration\Generators;
66

7+
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
78
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface;
89
use RZ\Roadiz\Typescript\Declaration\DeclarationGeneratorFactory;
910

@@ -19,6 +20,7 @@ final class DeclarationGenerator
1920
*/
2021
public function __construct(
2122
private readonly DeclarationGeneratorFactory $generatorFactory,
23+
private readonly NodeTypeClassLocatorInterface $nodeTypeClassLocator,
2224
array $nodeTypes = [],
2325
) {
2426
if (empty($nodeTypes)) {
@@ -45,9 +47,7 @@ public function getContents(): string
4547

4648
private function getAllTypesInterface(): string
4749
{
48-
$nodeTypeNames = array_map(function (NodeTypeInterface $nodeType) {
49-
return $nodeType->getSourceEntityClassName();
50-
}, $this->nodeTypes);
50+
$nodeTypeNames = array_map($this->nodeTypeClassLocator->getSourceEntityClassName(...), $this->nodeTypes);
5151

5252
$nodeTypeNames = implode(' | ', $nodeTypeNames);
5353

src/Generators/DocumentsFieldGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
final class DocumentsFieldGenerator extends AbstractFieldGenerator
88
{
9+
#[\Override]
910
protected function getNullableAssertion(): string
1011
{
1112
return ''; // always available even if empty
1213
}
1314

15+
#[\Override]
1416
protected function getType(): string
1517
{
1618
return 'Array<RoadizDocument>';

src/Generators/EnumFieldGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
final class EnumFieldGenerator extends AbstractFieldGenerator
88
{
9+
#[\Override]
910
protected function getType(): string
1011
{
1112
switch (true) {
1213
case $this->field->isEnum():
1314
$defaultValues = $this->field->getDefaultValuesAsArray();
1415
if (!empty($defaultValues) && count($defaultValues) > 0) {
15-
$defaultValues = array_map(function (string $value) {
16-
return '\''.$value.'\'';
17-
}, $defaultValues);
16+
$defaultValues = array_map(fn (string $value) => '\''.$value.'\'', $defaultValues);
1817

1918
return implode(' | ', $defaultValues).' | null';
2019
}
@@ -27,6 +26,7 @@ protected function getType(): string
2726
}
2827
}
2928

29+
#[\Override]
3030
protected function getIntroductionLines(): array
3131
{
3232
$lines = parent::getIntroductionLines();

src/Generators/NodeReferencesFieldGenerator.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@
44

55
namespace RZ\Roadiz\Typescript\Declaration\Generators;
66

7+
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
8+
use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface;
79
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface;
10+
use Symfony\Component\HttpFoundation\ParameterBag;
811

912
final class NodeReferencesFieldGenerator extends AbstractFieldGenerator
1013
{
14+
public function __construct(
15+
private readonly NodeTypeClassLocatorInterface $nodeTypeClassLocator,
16+
NodeTypeFieldInterface $field,
17+
ParameterBag $nodeTypesBag,
18+
) {
19+
parent::__construct($field, $nodeTypesBag);
20+
}
21+
22+
#[\Override]
1123
protected function getNullableAssertion(): string
1224
{
1325
return ''; // always available even if empty
1426
}
1527

28+
#[\Override]
1629
protected function getType(): string
1730
{
1831
return 'Array<'.$this->getUnionType().'>';
@@ -44,11 +57,10 @@ private function getUnionType(): string
4457
return 'RoadizNodesSources';
4558
}
4659

47-
return implode(' | ', array_map(function (NodeTypeInterface $nodeType) {
48-
return $nodeType->getSourceEntityClassName();
49-
}, $nodeTypes));
60+
return implode(' | ', array_map($this->nodeTypeClassLocator->getSourceEntityClassName(...), $nodeTypes));
5061
}
5162

63+
#[\Override]
5264
protected function getIntroductionLines(): array
5365
{
5466
$lines = parent::getIntroductionLines();

0 commit comments

Comments
 (0)