Skip to content

Commit

Permalink
Merge branch hotfix/v2.3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Jun 26, 2024
1 parent 3c4b1ca commit b55b6a1
Show file tree
Hide file tree
Showing 25 changed files with 541 additions and 614 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.0', '8.1']
php-version: ['8.1', '8.2', '8.3']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -39,5 +39,5 @@ jobs:
run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
- name: Run atoum unit tests
run: vendor/bin/atoum -f tests/units/*
- name: Run unit tests
run: vendor/bin/phpunit -v --whitelist ./src --coverage-clover ./build/logs/clover.xml src/Test
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test:
vendor/bin/phpcbf --report=full --report-file=./report.txt --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
vendor/bin/phpstan analyse -c phpstan.neon
vendor/bin/atoum -f tests/units/*
vendor/bin/phpunit -v --whitelist ./src --coverage-clover ./build/logs/clover.xml src/Test
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
}
],
"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-json": "*",
"roadiz/nodetype-contracts": "~1.1.2",
"symfony/string": "5.4.*",
"symfony/yaml": "5.4.*",
"symfony/serializer": "5.4.*",
"symfony/options-resolver": "5.4.*"
"symfony/string": "6.4.*",
"symfony/yaml": "6.4.*",
"symfony/serializer": "6.4.*",
"symfony/options-resolver": "6.4.*"
},
"suggest": {
"api-platform/core": "If you need to create ApiFilter annotation right into your entities"
Expand All @@ -32,13 +32,13 @@
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.5.3",
"atoum/atoum": "^4.0.0",
"api-platform/core": "~2.7.0"
"phpunit/phpunit": "^9.5",
"api-platform/core": "~3.2.14"
},
"extra": {
"branch-alias": {
"dev-main": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
"dev-main": "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,11 +1,12 @@
parameters:
level: max
level: 7
paths:
- src
excludePaths:
- */node_modules/*
- */bower_components/*
- */static/*
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
83 changes: 61 additions & 22 deletions src/Attribute/AttributeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class AttributeGenerator
{
protected string $className;
/**
* @var array<string|int, string|int>
* @var array<string|int, string|int|array>
*/
protected array $parameters;

/**
* @param string $className
* @param int[]|string[] $parameters
* @param array<string|int, string|int|array|null> $parameters
*/
public function __construct(string $className, array $parameters = [])
{
Expand All @@ -24,55 +24,94 @@ public function __construct(string $className, array $parameters = [])

public static function wrapString(string $string): string
{
return sprintf('"%s"', $string);
return sprintf('"%s"', str_replace('"', '\\"', $string));
}

public function generate(int $currentIndentation = 0): string
{
$formattedParams = [];
if (count($this->parameters) > 3) {
foreach ($this->parameters as $name => $parameter) {
if (is_string($name) && !empty($name)) {
$formattedParams[] = sprintf(
'%s%s: %s',
str_repeat(' ', $currentIndentation + 4),
$name,
$parameter
);
} else {
$formattedParams[] = sprintf(
'%s%s',
str_repeat(' ', $currentIndentation + 4),
$parameter
);
if (empty($parameter)) {
continue;
}
$formattedParams[] = $this->formatProperties($name, $parameter, $currentIndentation);
}
return
str_repeat(' ', $currentIndentation) .
$this->className .
sprintf(
'(%s%s%s)',
PHP_EOL,
implode(',' . PHP_EOL, $formattedParams),
implode(',' . PHP_EOL, array_filter($formattedParams)),
PHP_EOL . str_repeat(' ', $currentIndentation),
);
} elseif (count($this->parameters) > 0) {
foreach ($this->parameters as $name => $parameter) {
if (is_string($name) && !empty($name)) {
$formattedParams[] = sprintf('%s: %s', $name, $parameter);
} else {
$formattedParams[] = $parameter;
if (empty($parameter)) {
continue;
}
$formattedParams[] = $this->formatProperties($name, $parameter, -4);
}
return
str_repeat(' ', $currentIndentation) .
$this->className .
sprintf(
'(%s)',
implode(', ', $formattedParams)
implode(', ', array_filter($formattedParams))
);
} else {
return str_repeat(' ', $currentIndentation) . $this->className;
}
}

/**
* @param string $name
* @param array<string, mixed> $parameter
* @param int $currentIndentation
* @return string
* @throws \JsonException
*/
protected function formatArrayObject(string $name, array $parameter, int $currentIndentation = 0): string
{
$encodedParameterContent = [];
foreach ($parameter as $key => $value) {
if (is_string($key)) {
$encodedParameterContent[] = sprintf(
'%s => %s',
self::wrapString($key),
\json_encode($value, \JSON_THROW_ON_ERROR)
);
}
}
return sprintf(
'%s%s: %s',
str_repeat(' ', $currentIndentation + 4),
$name,
'[' . implode(', ', $encodedParameterContent) . ']'
);
}

protected function formatProperties(string|int $name, mixed $parameter, int $currentIndentation = 0): ?string
{
if (empty($parameter)) {
return null;
}
if (is_string($name) && \is_array($parameter)) {
return $this->formatArrayObject($name, $parameter, $currentIndentation);
}
if (is_string($name) && !empty($name)) {
return sprintf(
'%s%s: %s',
str_repeat(' ', $currentIndentation + 4),
$name,
$parameter
);
}
return sprintf(
'%s%s',
str_repeat(' ', $currentIndentation + 4),
$parameter
);
}
}
15 changes: 10 additions & 5 deletions src/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ protected function getClassHeader(): string
];

if ($this->options['use_api_platform_filters'] === true) {
$useStatements[] = 'use ApiPlatform\Core\Annotation\ApiFilter;';
$useStatements[] = 'use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter as OrmFilter;';
$useStatements[] = 'use ApiPlatform\Core\Serializer\Filter\PropertyFilter;';
$useStatements[] = 'use ApiPlatform\Metadata\ApiFilter;';
$useStatements[] = 'use ApiPlatform\Doctrine\Orm\Filter as OrmFilter;';
$useStatements[] = 'use ApiPlatform\Serializer\Filter\PropertyFilter;';
}
/*
* BE CAREFUL, USE statements are required for field generators which
Expand Down Expand Up @@ -247,10 +247,15 @@ protected function getClassAttributes(): string
*/
protected function getClassAnnotations(): string
{
$annotations = [
$this->nodeType->getName() . ' node-source entity.',
$this->nodeType->getDescription()
];
$annotations = array_filter($annotations);

return '
/**
* DO NOT EDIT
* Generated custom node-source type by Roadiz.
* ' . implode(PHP_EOL . ' * ', $annotations) . '
*/' . PHP_EOL;
}

Expand Down
21 changes: 21 additions & 0 deletions src/Field/AbstractFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ protected function getFieldAttributes(bool $exclude = false): array
$attributes[] = new AttributeGenerator('SymfonySerializer\Groups', [
$this->getSerializationGroups()
]);

$description = $this->field->getLabel();
if (!empty($this->field->getDescription())) {
$description .= ': ' . $this->field->getDescription();
}
if ($this->field->isEnum() && null !== $defaultValues = $this->field->getDefaultValues()) {
$enumValues = explode(',', $defaultValues);
$enumValues = array_filter(array_map('trim', $enumValues));
$openapiContext = [
'type' => 'string',
'enum' => $enumValues,
'example' => $enumValues[0] ?? null,
];
}
$attributes[] = new AttributeGenerator('\ApiPlatform\Metadata\ApiProperty', [
'description' => AttributeGenerator::wrapString($description),
'schema' => $openapiContext ?? null,
'example' => $this->field->getPlaceholder() ?
AttributeGenerator::wrapString($this->field->getPlaceholder()) :
null,
]);
if ($this->getSerializationMaxDepth() > 0) {
$attributes[] = new AttributeGenerator('SymfonySerializer\MaxDepth', [
$this->getSerializationMaxDepth()
Expand Down
35 changes: 12 additions & 23 deletions src/Field/CustomFormsFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,12 @@ public function getFieldGetter(): string
public function ' . $this->field->getGetterName() . '(): array
{
if (null === $this->' . $this->field->getVarName() . ') {
if (
null !== $this->objectManager &&
null !== $this->getNode() &&
null !== $this->getNode()->getNodeType()
) {
if (null !== $this->objectManager) {
$this->' . $this->field->getVarName() . ' = $this->objectManager
->getRepository(' . $this->options['custom_form_class'] . '::class)
->findByNodeAndField(
->findByNodeAndFieldName(
$this->getNode(),
$this->getNode()->getNodeType()->getFieldByName("' . $this->field->getName() . '")
\'' . $this->field->getName() . '\'
);
} else {
$this->' . $this->field->getVarName() . ' = [];
Expand All @@ -84,22 +80,15 @@ protected function getFieldSetter(): string
*/
public function add' . ucfirst($this->field->getVarName()) . '(' . $this->options['custom_form_class'] . ' $customForm): static
{
if (
null !== $this->objectManager &&
null !== $this->getNode() &&
null !== $this->getNode()->getNodeType()
) {
$field = $this->getNode()->getNodeType()->getFieldByName("' . $this->field->getName() . '");
if (null !== $field) {
$nodeCustomForm = new ' . $this->options['custom_form_proxy_class'] . '(
$this->getNode(),
$customForm,
$field
);
$this->objectManager->persist($nodeCustomForm);
$this->getNode()->addCustomForm($nodeCustomForm);
$this->' . $this->field->getVarName() . ' = null;
}
if (null !== $this->objectManager) {
$nodeCustomForm = new ' . $this->options['custom_form_proxy_class'] . '(
$this->getNode(),
$customForm
);
$nodeCustomForm->setFieldName(\'' . $this->field->getName() . '\');
$this->objectManager->persist($nodeCustomForm);
$this->getNode()->addCustomForm($nodeCustomForm);
$this->' . $this->field->getVarName() . ' = null;
}
return $this;
}' . PHP_EOL;
Expand Down
Loading

0 comments on commit b55b6a1

Please sign in to comment.