Skip to content

Commit f2f6473

Browse files
author
roadiz-ci
committed
Merge branch hotfix/v2.7.33
1 parent acd5e23 commit f2f6473

14 files changed

Lines changed: 94 additions & 124 deletions

.github/workflows/run-test.yml

Lines changed: 1 addition & 4 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.1', '8.2', '8.3']
22+
php-version: ['8.3', '8.4', '8.5']
2423
steps:
2524
- uses: shivammathur/setup-php@v2
2625
with:
@@ -36,7 +35,5 @@ jobs:
3635
${{ runner.os }}-php-${{ matrix.php-version }}-
3736
- name: Install Dependencies
3837
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
39-
- name: Run PHP Code Sniffer
40-
run: vendor/bin/phpcs -p ./src
4138
- name: Run PHPStan
4239
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon

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

Makefile

Lines changed: 0 additions & 4 deletions
This file was deleted.

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"description": "Roadiz sub-package which generates Typescript interfaces skeleton based on your schema",
44
"type": "library",
55
"require": {
6-
"roadiz/nodetype-contracts": "~1.1.2",
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",
11-
"squizlabs/php_codesniffer": "^3.5"
10+
"phpstan/phpstan": "^2.1.36",
11+
"phpstan/phpdoc-parser": "<2"
1212
},
1313
"license": "MIT",
1414
"authors": [
@@ -26,8 +26,8 @@
2626
},
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "2.3.x-dev",
30-
"dev-develop": "2.4.x-dev"
29+
"dev-master": "2.7.x-dev",
30+
"dev-develop": "2.8.x-dev"
3131
}
3232
}
3333
}

phpcs.xml.dist

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/DeclarationGeneratorFactory.php

Lines changed: 9 additions & 18 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;
@@ -15,15 +16,14 @@
1516
use RZ\Roadiz\Typescript\Declaration\Generators\ScalarFieldGenerator;
1617
use Symfony\Component\HttpFoundation\ParameterBag;
1718

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

24-
/**
25-
* @return ParameterBag
26-
*/
2727
public function getNodeTypesBag(): ParameterBag
2828
{
2929
return $this->nodeTypesBag;
@@ -34,29 +34,20 @@ public function getHumanBool(bool $bool): string
3434
return $bool ? 'true' : 'false';
3535
}
3636

37-
/**
38-
* @param NodeTypeInterface $nodeType
39-
*
40-
* @return NodeTypeGenerator
41-
*/
4237
public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerator
4338
{
4439
return new NodeTypeGenerator(
4540
$nodeType,
46-
$this
41+
$this,
42+
$this->nodeTypeClassLocator
4743
);
4844
}
4945

50-
/**
51-
* @param NodeTypeFieldInterface $field
52-
*
53-
* @return AbstractFieldGenerator
54-
*/
5546
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
5647
{
5748
return match (true) {
5849
$field->isDocuments() => new DocumentsFieldGenerator($field, $this->nodeTypesBag),
59-
$field->isNodes() => new NodeReferencesFieldGenerator($field, $this->nodeTypesBag),
50+
$field->isNodes() => new NodeReferencesFieldGenerator($this->nodeTypeClassLocator, $field, $this->nodeTypesBag),
6051
$field->isChildrenNodes() => new ChildrenNodeFieldGenerator($field, $this->nodeTypesBag),
6152
$field->isMultiple(), $field->isEnum() => new EnumFieldGenerator($field, $this->nodeTypesBag),
6253
default => new ScalarFieldGenerator($field, $this->nodeTypesBag),

src/Generators/AbstractFieldGenerator.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,10 @@ abstract class AbstractFieldGenerator
1212
// Four spaces
1313
public const INDENTATION_MARK = ' ';
1414

15-
protected NodeTypeFieldInterface $field;
16-
protected ParameterBag $nodeTypesBag;
17-
18-
/**
19-
* @param NodeTypeFieldInterface $field
20-
* @param ParameterBag $nodeTypesBag
21-
*/
2215
public function __construct(
23-
NodeTypeFieldInterface $field,
24-
ParameterBag $nodeTypesBag
16+
protected readonly NodeTypeFieldInterface $field,
17+
protected readonly ParameterBag $nodeTypesBag,
2518
) {
26-
$this->field = $field;
27-
$this->nodeTypesBag = $nodeTypesBag;
2819
}
2920

3021
protected function getNullableAssertion(): string
@@ -36,18 +27,18 @@ abstract protected function getType(): string;
3627

3728
private function getDeclaration(): string
3829
{
39-
return static::INDENTATION_MARK .
40-
$this->field->getVarName() .
41-
$this->getNullableAssertion() . ': ' .
30+
return static::INDENTATION_MARK.
31+
$this->field->getVarName().
32+
$this->getNullableAssertion().': '.
4233
$this->getType();
4334
}
4435

4536
public function getContents(): string
4637
{
4738
return implode(PHP_EOL, [
48-
$this->getIntroduction(),
49-
$this->getDeclaration()
50-
]);
39+
$this->getIntroduction(),
40+
$this->getDeclaration(),
41+
]);
5142
}
5243

5344
protected function getIntroductionLines(): array
@@ -60,19 +51,14 @@ protected function getIntroductionLines(): array
6051
}
6152

6253
if (!empty($this->field->getGroupName())) {
63-
$lines[] = 'Group: ' . $this->field->getGroupName();
54+
$lines[] = 'Group: '.$this->field->getGroupName();
6455
}
6556

6657
return $lines;
6758
}
6859

69-
/**
70-
* @return string
71-
*/
7260
public function getIntroduction(): string
7361
{
74-
return implode(PHP_EOL, array_map(function (string $line) {
75-
return static::INDENTATION_MARK . '// ' . $line;
76-
}, $this->getIntroductionLines()));
62+
return implode(PHP_EOL, array_map(fn (string $line) => static::INDENTATION_MARK.'// '.$line, $this->getIntroductionLines()));
7763
}
7864
}

src/Generators/ChildrenNodeFieldGenerator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@
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
}
16+
17+
#[\Override]
1518
protected function getIntroductionLines(): array
1619
{
1720
$lines = [
18-
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks'
21+
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks',
1922
];
20-
if (!empty($this->field->getDefaultValues())) {
21-
$lines[] = 'Possible block node-types: ' . $this->field->getDefaultValues();
23+
if (!empty($this->field->getDefaultValuesAsArray())) {
24+
$lines[] = 'Possible block node-types: '.json_encode($this->field->getDefaultValuesAsArray());
2225
}
26+
2327
return $lines;
2428
}
2529

30+
#[\Override]
2631
protected function getType(): string
2732
{
2833
return '';

src/Generators/DeclarationGenerator.php

Lines changed: 5 additions & 6 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

@@ -15,12 +16,12 @@ final class DeclarationGenerator
1516
private array $nodeTypes;
1617

1718
/**
18-
* @param DeclarationGeneratorFactory $generatorFactory
1919
* @param NodeTypeInterface[] $nodeTypes
2020
*/
2121
public function __construct(
2222
private readonly DeclarationGeneratorFactory $generatorFactory,
23-
array $nodeTypes = []
23+
private readonly NodeTypeClassLocatorInterface $nodeTypeClassLocator,
24+
array $nodeTypes = [],
2425
) {
2526
if (empty($nodeTypes)) {
2627
$this->nodeTypes = array_unique($this->generatorFactory->getNodeTypesBag()->all());
@@ -41,14 +42,12 @@ public function getContents(): string
4142

4243
$blocks[] = $this->getAllTypesInterface();
4344

44-
return implode(PHP_EOL . PHP_EOL, $blocks);
45+
return implode(PHP_EOL.PHP_EOL, $blocks);
4546
}
4647

4748
private function getAllTypesInterface(): string
4849
{
49-
$nodeTypeNames = array_map(function (NodeTypeInterface $nodeType) {
50-
return $nodeType->getSourceEntityClassName();
51-
}, $this->nodeTypes);
50+
$nodeTypeNames = array_map($this->nodeTypeClassLocator->getSourceEntityClassName(...), $this->nodeTypes);
5251

5352
$nodeTypeNames = implode(' | ', $nodeTypeNames);
5453

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>';

0 commit comments

Comments
 (0)