Skip to content

Commit 2ff5b67

Browse files
author
roadiz-ci
committed
chore: bumped
1 parent a18ce4a commit 2ff5b67

11 files changed

Lines changed: 57 additions & 104 deletions

.github/workflows/run-test.yml

Lines changed: 1 addition & 3 deletions
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.1', '8.2', '8.3']
23+
php-version: ['8.2', '8.3']
2424
steps:
2525
- uses: shivammathur/setup-php@v2
2626
with:
@@ -36,7 +36,5 @@ 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
4139
- name: Run PHPStan
4240
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon

Makefile

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

composer.json

Lines changed: 4 additions & 4 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",
6+
"roadiz/nodetype-contracts": "^2.0.0",
77
"symfony/http-foundation": "6.4.*"
88
},
99
"require-dev": {
1010
"phpstan/phpstan": "^1.5.3",
11-
"squizlabs/php_codesniffer": "^3.5"
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.5.x-dev",
30+
"dev-develop": "2.6.x-dev"
3131
}
3232
}
3333
}

phpcs.xml.dist

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

src/DeclarationGeneratorFactory.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
use RZ\Roadiz\Typescript\Declaration\Generators\ScalarFieldGenerator;
1616
use Symfony\Component\HttpFoundation\ParameterBag;
1717

18-
final class DeclarationGeneratorFactory
18+
final readonly class DeclarationGeneratorFactory
1919
{
20-
public function __construct(private readonly ParameterBag $nodeTypesBag)
20+
public function __construct(private ParameterBag $nodeTypesBag)
2121
{
2222
}
2323

24-
/**
25-
* @return ParameterBag
26-
*/
2724
public function getNodeTypesBag(): ParameterBag
2825
{
2926
return $this->nodeTypesBag;
@@ -34,11 +31,6 @@ public function getHumanBool(bool $bool): string
3431
return $bool ? 'true' : 'false';
3532
}
3633

37-
/**
38-
* @param NodeTypeInterface $nodeType
39-
*
40-
* @return NodeTypeGenerator
41-
*/
4234
public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerator
4335
{
4436
return new NodeTypeGenerator(
@@ -47,11 +39,6 @@ public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerato
4739
);
4840
}
4941

50-
/**
51-
* @param NodeTypeFieldInterface $field
52-
*
53-
* @return AbstractFieldGenerator
54-
*/
5542
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
5643
{
5744
return match (true) {

src/Generators/AbstractFieldGenerator.php

Lines changed: 10 additions & 22 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,16 @@ 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
{
7462
return implode(PHP_EOL, array_map(function (string $line) {
75-
return static::INDENTATION_MARK . '// ' . $line;
63+
return static::INDENTATION_MARK.'// '.$line;
7664
}, $this->getIntroductionLines()));
7765
}
7866
}

src/Generators/ChildrenNodeFieldGenerator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ public function getContents(): string
1212
$this->getIntroduction(),
1313
]);
1414
}
15+
1516
protected function getIntroductionLines(): array
1617
{
1718
$lines = [
18-
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks'
19+
'This node-type uses "blocks" which are available through parent RoadizNodesSources.blocks',
1920
];
20-
if (!empty($this->field->getDefaultValues())) {
21-
$lines[] = 'Possible block node-types: ' . $this->field->getDefaultValues();
21+
if (!empty($this->field->getDefaultValuesAsArray())) {
22+
$lines[] = 'Possible block node-types: '.json_encode($this->field->getDefaultValuesAsArray());
2223
}
24+
2325
return $lines;
2426
}
2527

src/Generators/DeclarationGenerator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ final class DeclarationGenerator
1515
private array $nodeTypes;
1616

1717
/**
18-
* @param DeclarationGeneratorFactory $generatorFactory
1918
* @param NodeTypeInterface[] $nodeTypes
2019
*/
2120
public function __construct(
2221
private readonly DeclarationGeneratorFactory $generatorFactory,
23-
array $nodeTypes = []
22+
array $nodeTypes = [],
2423
) {
2524
if (empty($nodeTypes)) {
2625
$this->nodeTypes = array_unique($this->generatorFactory->getNodeTypesBag()->all());
@@ -41,7 +40,7 @@ public function getContents(): string
4140

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

44-
return implode(PHP_EOL . PHP_EOL, $blocks);
43+
return implode(PHP_EOL.PHP_EOL, $blocks);
4544
}
4645

4746
private function getAllTypesInterface(): string

src/Generators/EnumFieldGenerator.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@ protected function getType(): string
1010
{
1111
switch (true) {
1212
case $this->field->isEnum():
13-
if (!empty($this->field->getDefaultValues())) {
14-
$defaultValues = array_filter(
15-
array_map(
16-
'trim',
17-
explode(',', $this->field->getDefaultValues())
18-
)
19-
);
20-
if (count($defaultValues) > 0) {
21-
$defaultValues = array_map(function (string $value) {
22-
return '\'' . $value . '\'';
23-
}, $defaultValues);
24-
return implode(' | ', $defaultValues) . ' | null';
25-
}
13+
$defaultValues = $this->field->getDefaultValuesAsArray();
14+
if (!empty($defaultValues) && count($defaultValues) > 0) {
15+
$defaultValues = array_map(function (string $value) {
16+
return '\''.$value.'\'';
17+
}, $defaultValues);
18+
19+
return implode(' | ', $defaultValues).' | null';
2620
}
21+
2722
return 'string';
2823
case $this->field->isMultiple():
2924
return 'Array<string>';
@@ -35,9 +30,10 @@ protected function getType(): string
3530
protected function getIntroductionLines(): array
3631
{
3732
$lines = parent::getIntroductionLines();
38-
if (!empty($this->field->getDefaultValues())) {
39-
$lines[] = 'Possible values: ' . $this->field->getDefaultValues();
33+
if (!empty($this->field->getDefaultValuesAsArray())) {
34+
$lines[] = 'Possible values: '.json_encode($this->field->getDefaultValuesAsArray());
4035
}
36+
4137
return $lines;
4238
}
4339
}

src/Generators/NodeReferencesFieldGenerator.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@ protected function getNullableAssertion(): string
1515

1616
protected function getType(): string
1717
{
18-
return 'Array<' . $this->getUnionType() . '>';
18+
return 'Array<'.$this->getUnionType().'>';
1919
}
2020

2121
/**
2222
* @return array<NodeTypeInterface>
2323
*/
2424
private function getLinkedNodeTypes(): array
2525
{
26-
if (null === $this->field->getDefaultValues()) {
27-
return [];
26+
$nodeTypeNames = $this->field->getDefaultValuesAsArray();
27+
28+
if (0 === count($nodeTypeNames)) {
29+
return $nodeTypeNames;
2830
}
29-
$nodeTypeNames = explode(',', $this->field->getDefaultValues());
31+
3032
return array_values(array_filter(array_map(function (string $name) {
3133
$nodeType = $this->nodeTypesBag->get(trim($name));
34+
3235
return $nodeType instanceof NodeTypeInterface ? $nodeType : null;
3336
}, $nodeTypeNames)));
3437
}
@@ -49,9 +52,10 @@ private function getUnionType(): string
4952
protected function getIntroductionLines(): array
5053
{
5154
$lines = parent::getIntroductionLines();
52-
if (!empty($this->field->getDefaultValues())) {
53-
$lines[] = 'Possible values: ' . $this->field->getDefaultValues();
55+
if (!empty($this->field->getDefaultValuesAsArray())) {
56+
$lines[] = 'Possible values: '.json_encode($this->field->getDefaultValuesAsArray());
5457
}
58+
5559
return $lines;
5660
}
5761
}

0 commit comments

Comments
 (0)