Skip to content

Commit

Permalink
chore: Bumped
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Oct 11, 2024
1 parent 9339e25 commit 225e341
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 39 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 © 2024 Ambroise Maupate
Copyright © 2023 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": "6.4.*"
"symfony/http-foundation": "5.4.*"
},
"require-dev": {
"phpstan/phpstan": "^1.5.3",
Expand All @@ -26,8 +26,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
"dev-master": "2.2.x-dev",
"dev-develop": "2.3.x-dev"
}
}
}
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
parameters:
level: 7
level: max
paths:
- src
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
28 changes: 20 additions & 8 deletions src/DeclarationGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@

final class DeclarationGeneratorFactory
{
public function __construct(private readonly ParameterBag $nodeTypesBag)
private ParameterBag $nodeTypesBag;

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

/**
Expand Down Expand Up @@ -54,12 +60,18 @@ public function createForNodeType(NodeTypeInterface $nodeType): NodeTypeGenerato
*/
public function createForNodeTypeField(NodeTypeFieldInterface $field): AbstractFieldGenerator
{
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),
};
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);
}
}
}
9 changes: 5 additions & 4 deletions src/Generators/DeclarationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

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

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

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

/** @var NodeTypeFieldInterface $field */
foreach ($this->nodeType->getFields() as $field) {
Expand Down
42 changes: 25 additions & 17 deletions src/Generators/ScalarFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ final class ScalarFieldGenerator extends AbstractFieldGenerator
{
protected function getType(): string
{
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',
};
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';
}
}
}

0 comments on commit 225e341

Please sign in to comment.