Skip to content

Commit

Permalink
chore: Bumped
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Sep 24, 2024
1 parent 7501ef4 commit 99e4bed
Show file tree
Hide file tree
Showing 27 changed files with 669 additions and 589 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.1', '8.2', '8.3']
php-version: ['8.0', '8.1']
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 unit tests
run: vendor/bin/phpunit -v --whitelist ./src tests
- name: Run atoum unit tests
run: vendor/bin/atoum -f tests/units/*
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: php
sudo: required
php:
- 8.0
- 8.1
- nightly
env:
- XDEBUG_MODE=coverage
install:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev --no-interaction
script:
- vendor/bin/phpcs --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/*
jobs:
allow_failures:
- php: nightly
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Roadiz

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.
9 changes: 0 additions & 9 deletions LICENSE.md

This file was deleted.

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +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/*
26 changes: 11 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,33 @@
}
],
"require": {
"php": ">=8.1",
"php": ">=8.0",
"ext-json": "*",
"roadiz/nodetype-contracts": "~1.1.2",
"symfony/string": "6.4.*",
"symfony/yaml": "6.4.*",
"symfony/serializer": "6.4.*",
"symfony/options-resolver": "6.4.*"
"symfony/string": "5.4.*",
"symfony/yaml": "5.4.*",
"symfony/serializer": "5.4.*",
"symfony/options-resolver": "5.4.*"
},
"suggest": {
"api-platform/core": "If you need to create ApiFilter annotation right into your entities"
},
"autoload": {
"psr-4": {
"RZ\\Roadiz\\EntityGenerator\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"RZ\\Roadiz\\EntityGenerator\\Tests\\": "tests/"
"RZ\\Roadiz\\EntityGenerator\\": "src/",
"tests\\mocks\\": "tests/mocks/"
}
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^1.5.3",
"phpunit/phpunit": "^9.5",
"api-platform/core": "~3.2.14"
"atoum/atoum": "^4.0.0",
"api-platform/core": "~2.7.0"
},
"extra": {
"branch-alias": {
"dev-main": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
"dev-main": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
}
}
}
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
parameters:
level: 7
level: max
paths:
- src
excludePaths:
- */node_modules/*
- */bower_components/*
- */static/*
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
83 changes: 22 additions & 61 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|array>
* @var array<string|int, string|int>
*/
protected array $parameters;

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

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

public function generate(int $currentIndentation = 0): string
{
$formattedParams = [];
if (count($this->parameters) > 3) {
foreach ($this->parameters as $name => $parameter) {
if (empty($parameter)) {
continue;
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
);
}
$formattedParams[] = $this->formatProperties($name, $parameter, $currentIndentation);
}
return
str_repeat(' ', $currentIndentation) .
$this->className .
sprintf(
'(%s%s%s)',
PHP_EOL,
implode(',' . PHP_EOL, array_filter($formattedParams)),
implode(',' . PHP_EOL, $formattedParams),
PHP_EOL . str_repeat(' ', $currentIndentation),
);
} elseif (count($this->parameters) > 0) {
foreach ($this->parameters as $name => $parameter) {
if (empty($parameter)) {
continue;
if (is_string($name) && !empty($name)) {
$formattedParams[] = sprintf('%s: %s', $name, $parameter);
} else {
$formattedParams[] = $parameter;
}
$formattedParams[] = $this->formatProperties($name, $parameter, -4);
}
return
str_repeat(' ', $currentIndentation) .
$this->className .
sprintf(
'(%s)',
implode(', ', array_filter($formattedParams))
implode(', ', $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: 5 additions & 10 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\Metadata\ApiFilter;';
$useStatements[] = 'use ApiPlatform\Doctrine\Orm\Filter as OrmFilter;';
$useStatements[] = 'use ApiPlatform\Serializer\Filter\PropertyFilter;';
$useStatements[] = 'use ApiPlatform\Core\Annotation\ApiFilter;';
$useStatements[] = 'use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter as OrmFilter;';
$useStatements[] = 'use ApiPlatform\Core\Serializer\Filter\PropertyFilter;';
}
/*
* BE CAREFUL, USE statements are required for field generators which
Expand Down Expand Up @@ -247,15 +247,10 @@ protected function getClassAttributes(): string
*/
protected function getClassAnnotations(): string
{
$annotations = [
$this->nodeType->getName() . ' node-source entity.',
$this->nodeType->getDescription()
];
$annotations = array_filter($annotations);

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

Expand Down
13 changes: 10 additions & 3 deletions src/EntityGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@

final class EntityGeneratorFactory
{
private NodeTypeResolverInterface $nodeTypeResolverBag;
private DefaultValuesResolverInterface $defaultValuesResolver;
private array $options;

public function __construct(
private readonly NodeTypeResolverInterface $nodeTypeResolverBag,
private readonly DefaultValuesResolverInterface $defaultValuesResolver,
private readonly array $options
NodeTypeResolverInterface $nodeTypeResolverBag,
DefaultValuesResolverInterface $defaultValuesResolver,
array $options
) {
$this->nodeTypeResolverBag = $nodeTypeResolverBag;
$this->defaultValuesResolver = $defaultValuesResolver;
$this->options = $options;
}

public function create(NodeTypeInterface $nodeType): EntityGeneratorInterface
Expand Down
21 changes: 0 additions & 21 deletions src/Field/AbstractFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,6 @@ 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
Loading

0 comments on commit 99e4bed

Please sign in to comment.