Skip to content

Commit a18ce4a

Browse files
author
roadiz-ci
committed
chore: bumped
1 parent 5924b46 commit a18ce4a

14 files changed

Lines changed: 123 additions & 94 deletions

.github/workflows/run-test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
php-version: ['8.3', '8.4']
23+
php-version: ['8.1', '8.2', '8.3']
2424
steps:
2525
- uses: shivammathur/setup-php@v2
2626
with:
@@ -36,5 +36,7 @@ jobs:
3636
${{ runner.os }}-php-${{ matrix.php-version }}-
3737
- name: Install Dependencies
3838
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
39+
- name: Run PHP Code Sniffer
40+
run: vendor/bin/phpcs -p ./src
3941
- name: Run PHPStan
4042
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 © 2025 Ambroise Maupate
3+
Copyright © 2024 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test:
2+
vendor/bin/phpcbf --report=full --report-file=./report.txt -p ./
3+
vendor/bin/phpstan analyse -c phpstan.neon
4+

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": "^3.1.1",
7-
"symfony/http-foundation": "7.4.*"
6+
"roadiz/nodetype-contracts": "~1.1.2",
7+
"symfony/http-foundation": "6.4.*"
88
},
99
"require-dev": {
10-
"phpstan/phpstan": "^2.1.36",
11-
"phpstan/phpdoc-parser": "<2"
10+
"phpstan/phpstan": "^1.5.3",
11+
"squizlabs/php_codesniffer": "^3.5"
1212
},
1313
"license": "MIT",
1414
"authors": [
@@ -26,8 +26,8 @@
2626
},
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "2.7.x-dev",
30-
"dev-develop": "2.8.x-dev"
29+
"dev-master": "2.3.x-dev",
30+
"dev-develop": "2.4.x-dev"
3131
}
3232
}
3333
}

phpcs.xml.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg name="extensions" value="php"/>
9+
10+
<rule ref="PSR12">
11+
<exclude name="Generic.Files.LineLength"/>
12+
</rule>
13+
<file>./src</file>
14+
<exclude-pattern>*/node_modules</exclude-pattern>
15+
<exclude-pattern>*/.AppleDouble</exclude-pattern>
16+
<exclude-pattern>*/vendor</exclude-pattern>
17+
</ruleset>

src/DeclarationGeneratorFactory.php

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

55
namespace RZ\Roadiz\Typescript\Declaration;
66

7-
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
87
use RZ\Roadiz\Contracts\NodeType\NodeTypeFieldInterface;
98
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface;
109
use RZ\Roadiz\Typescript\Declaration\Generators\AbstractFieldGenerator;
@@ -16,14 +15,15 @@
1615
use RZ\Roadiz\Typescript\Declaration\Generators\ScalarFieldGenerator;
1716
use Symfony\Component\HttpFoundation\ParameterBag;
1817

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

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

37+
/**
38+
* @param NodeTypeInterface $nodeType
39+
*
40+
* @return NodeTypeGenerator
41+
*/
3742
public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerator
3843
{
3944
return new NodeTypeGenerator(
4045
$nodeType,
41-
$this,
42-
$this->nodeTypeClassLocator
46+
$this
4347
);
4448
}
4549

50+
/**
51+
* @param NodeTypeFieldInterface $field
52+
*
53+
* @return AbstractFieldGenerator
54+
*/
4655
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
4756
{
4857
return match (true) {
4958
$field->isDocuments() => new DocumentsFieldGenerator($field, $this->nodeTypesBag),
50-
$field->isNodes() => new NodeReferencesFieldGenerator($this->nodeTypeClassLocator, $field, $this->nodeTypesBag),
59+
$field->isNodes() => new NodeReferencesFieldGenerator($field, $this->nodeTypesBag),
5160
$field->isChildrenNodes() => new ChildrenNodeFieldGenerator($field, $this->nodeTypesBag),
5261
$field->isMultiple(), $field->isEnum() => new EnumFieldGenerator($field, $this->nodeTypesBag),
5362
default => new ScalarFieldGenerator($field, $this->nodeTypesBag),

src/Generators/AbstractFieldGenerator.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ 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+
*/
1522
public function __construct(
16-
protected readonly NodeTypeFieldInterface $field,
17-
protected readonly ParameterBag $nodeTypesBag,
23+
NodeTypeFieldInterface $field,
24+
ParameterBag $nodeTypesBag
1825
) {
26+
$this->field = $field;
27+
$this->nodeTypesBag = $nodeTypesBag;
1928
}
2029

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

2837
private function getDeclaration(): string
2938
{
30-
return static::INDENTATION_MARK.
31-
$this->field->getVarName().
32-
$this->getNullableAssertion().': '.
39+
return static::INDENTATION_MARK .
40+
$this->field->getVarName() .
41+
$this->getNullableAssertion() . ': ' .
3342
$this->getType();
3443
}
3544

3645
public function getContents(): string
3746
{
3847
return implode(PHP_EOL, [
39-
$this->getIntroduction(),
40-
$this->getDeclaration(),
41-
]);
48+
$this->getIntroduction(),
49+
$this->getDeclaration()
50+
]);
4251
}
4352

4453
protected function getIntroductionLines(): array
@@ -51,14 +60,19 @@ protected function getIntroductionLines(): array
5160
}
5261

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

5766
return $lines;
5867
}
5968

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

src/Generators/ChildrenNodeFieldGenerator.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,23 @@
66

77
final class ChildrenNodeFieldGenerator extends AbstractFieldGenerator
88
{
9-
#[\Override]
109
public function getContents(): string
1110
{
1211
return implode(PHP_EOL, [
1312
$this->getIntroduction(),
1413
]);
1514
}
16-
17-
#[\Override]
1815
protected function getIntroductionLines(): array
1916
{
2017
$lines = [
21-
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks',
18+
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks'
2219
];
23-
if (!empty($this->field->getDefaultValuesAsArray())) {
24-
$lines[] = 'Possible block node-types: '.json_encode($this->field->getDefaultValuesAsArray());
20+
if (!empty($this->field->getDefaultValues())) {
21+
$lines[] = 'Possible block node-types: ' . $this->field->getDefaultValues();
2522
}
26-
2723
return $lines;
2824
}
2925

30-
#[\Override]
3126
protected function getType(): string
3227
{
3328
return '';

src/Generators/DeclarationGenerator.php

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

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

7-
use RZ\Roadiz\Contracts\NodeType\NodeTypeClassLocatorInterface;
87
use RZ\Roadiz\Contracts\NodeType\NodeTypeInterface;
98
use RZ\Roadiz\Typescript\Declaration\DeclarationGeneratorFactory;
109

@@ -16,12 +15,12 @@ final class DeclarationGenerator
1615
private array $nodeTypes;
1716

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

4342
$blocks[] = $this->getAllTypesInterface();
4443

45-
return implode(PHP_EOL.PHP_EOL, $blocks);
44+
return implode(PHP_EOL . PHP_EOL, $blocks);
4645
}
4746

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

5253
$nodeTypeNames = implode(' | ', $nodeTypeNames);
5354

src/Generators/DocumentsFieldGenerator.php

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

77
final class DocumentsFieldGenerator extends AbstractFieldGenerator
88
{
9-
#[\Override]
109
protected function getNullableAssertion(): string
1110
{
1211
return ''; // always available even if empty
1312
}
1413

15-
#[\Override]
1614
protected function getType(): string
1715
{
1816
return 'Array<RoadizDocument>';

0 commit comments

Comments
 (0)