Skip to content

Commit

Permalink
Merge branch hotfix/v2.3.28
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Sep 24, 2024
1 parent 410279e commit 02ad8dd
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 67 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright © 2023 Ambroise Maupate
Copyright © 2024 Ambroise Maupate

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:

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"require": {
"roadiz/nodetype-contracts": "~1.1.2",
"symfony/http-foundation": "5.4.*"
"symfony/http-foundation": "6.4.*"
},
"require-dev": {
"phpstan/phpstan": "^1.5.3",
Expand All @@ -26,8 +26,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.2.x-dev",
"dev-develop": "2.3.x-dev"
"dev-master": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
}
}
}
7 changes: 4 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
parameters:
level: max
level: 7
paths:
- src
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
28 changes: 8 additions & 20 deletions src/DeclarationGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@

final class DeclarationGeneratorFactory
{
private ParameterBag $nodeTypesBag;

/**
* @param ParameterBag $nodeTypesBag
*/
public function __construct(ParameterBag $nodeTypesBag)
public function __construct(private readonly ParameterBag $nodeTypesBag)
{
$this->nodeTypesBag = $nodeTypesBag;
}

/**
Expand Down Expand Up @@ -60,18 +54,12 @@ public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerato
*/
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
{
switch (true) {
case $field->isDocuments():
return new DocumentsFieldGenerator($field, $this->nodeTypesBag);
case $field->isNodes():
return new NodeReferencesFieldGenerator($field, $this->nodeTypesBag);
case $field->isChildrenNodes():
return new ChildrenNodeFieldGenerator($field, $this->nodeTypesBag);
case $field->isMultiple():
case $field->isEnum():
return new EnumFieldGenerator($field, $this->nodeTypesBag);
default:
return new ScalarFieldGenerator($field, $this->nodeTypesBag);
}
return match (true) {
$field->isDocuments() => new DocumentsFieldGenerator($field, $this->nodeTypesBag),
$field->isNodes() => new NodeReferencesFieldGenerator($field, $this->nodeTypesBag),
$field->isChildrenNodes() => new ChildrenNodeFieldGenerator($field, $this->nodeTypesBag),
$field->isMultiple(), $field->isEnum() => new EnumFieldGenerator($field, $this->nodeTypesBag),
default => new ScalarFieldGenerator($field, $this->nodeTypesBag),
};
}
}
9 changes: 4 additions & 5 deletions src/Generators/DeclarationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

final class DeclarationGenerator
{
private DeclarationGeneratorFactory $generatorFactory;
/**
* @var array<NodeTypeInterface>
*/
Expand All @@ -19,10 +18,10 @@ final class DeclarationGenerator
* @param DeclarationGeneratorFactory $generatorFactory
* @param NodeTypeInterface[] $nodeTypes
*/
public function __construct(DeclarationGeneratorFactory $generatorFactory, array $nodeTypes = [])
{
$this->generatorFactory = $generatorFactory;

public function __construct(
private readonly DeclarationGeneratorFactory $generatorFactory,
array $nodeTypes = []
) {
if (empty($nodeTypes)) {
$this->nodeTypes = array_unique($this->generatorFactory->getNodeTypesBag()->all());
} else {
Expand Down
12 changes: 2 additions & 10 deletions src/Generators/NodeTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,16 @@

final class NodeTypeGenerator
{
private NodeTypeInterface $nodeType;
/**
* @var array<AbstractFieldGenerator>
*/
private array $fieldGenerators;
private DeclarationGeneratorFactory $generatorFactory;

/**
* @param NodeTypeInterface $nodeType
* @param DeclarationGeneratorFactory $generatorFactory
*/
public function __construct(
NodeTypeInterface $nodeType,
DeclarationGeneratorFactory $generatorFactory
private readonly NodeTypeInterface $nodeType,
private readonly DeclarationGeneratorFactory $generatorFactory
) {
$this->nodeType = $nodeType;
$this->fieldGenerators = [];
$this->generatorFactory = $generatorFactory;

/** @var NodeTypeFieldInterface $field */
foreach ($this->nodeType->getFields() as $field) {
Expand Down
42 changes: 17 additions & 25 deletions src/Generators/ScalarFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,22 @@ final class ScalarFieldGenerator extends AbstractFieldGenerator
{
protected function getType(): string
{
switch (true) {
case $this->field->isString():
case $this->field->isRichText():
case $this->field->isText():
case $this->field->isMarkdown():
case $this->field->isCss():
case $this->field->isColor():
case $this->field->isCountry():
case $this->field->isDate():
case $this->field->isDateTime():
case $this->field->isGeoTag():
case $this->field->isMultiGeoTag():
return 'string';
case $this->field->isBool():
return 'boolean';
case $this->field->isDecimal():
case $this->field->isInteger():
return 'number';
case $this->field->isCollection():
case $this->field->isMultiProvider():
// Data cannot be known, this depends on user configuration
return 'Array<unknown>';
default:
return 'unknown';
}
return match (true) {
$this->field->isString(),
$this->field->isRichText(),
$this->field->isText(),
$this->field->isMarkdown(),
$this->field->isCss(),
$this->field->isColor(),
$this->field->isCountry(),
$this->field->isDate(),
$this->field->isDateTime(),
$this->field->isGeoTag(),
$this->field->isMultiGeoTag() => 'string',
$this->field->isBool() => 'boolean',
$this->field->isDecimal(), $this->field->isInteger() => 'number',
$this->field->isCollection(), $this->field->isMultiProvider() => 'Array<unknown>',
default => 'unknown',
};
}
}

0 comments on commit 02ad8dd

Please sign in to comment.