Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
strategy:
matrix:
include:
- php-version: 8.3
docker-image: 'anzusystems/php:4.0.0-php83-cli'
- php-version: 8.4
docker-image: 'anzusystems/php:5.0.1-php84-cli'
- php-version: 8.5
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
}
],
"require": {
"php": ">=8.3",
"php": ">=8.4",
"ext-json": "*",
"doctrine/common": "^3.3",
"nelmio/api-doc-bundle": "^5.9",
"symfony/property-info": "^6.3|^7.0"
"symfony/type-info": "^7.0|^8.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.18",
"doctrine/orm": "^3.5",
"slevomat/coding-standard": "8.22",
"symfony/dotenv": "^6.3|^7.0",
"symfony/dotenv": "^7.0|^8.0",
"symfony/test-pack": "^1.1",
"symfony/uid": "^6.3|^7.0",
"symfony/var-exporter": "^6.3|^7.0",
"symplify/easy-coding-standard": "^12.0",
"symfony/uid": "^7.0|^8.0",
"symfony/var-exporter": "^7.0|^8.0",
"symplify/easy-coding-standard": "^13.0",
"vimeo/psalm": "^6.8"
},
"suggest": {
Expand Down
231 changes: 82 additions & 149 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use AnzuSystems\SerializerBundle\DependencyInjection\Configuration;
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
Expand All @@ -14,24 +13,19 @@
use PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationIndentationFixer;
use PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationSpacesFixer;
use PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocTagRenameFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagNormalizerFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use SlevomatCodingStandard\Sniffs\Classes\MethodSpacingSniff;
use SlevomatCodingStandard\Sniffs\Classes\ModernClassNameReferenceSniff;
use SlevomatCodingStandard\Sniffs\Classes\ParentCallSpacingSniff;
use SlevomatCodingStandard\Sniffs\Classes\PropertySpacingSniff;
use SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff;
use SlevomatCodingStandard\Sniffs\Commenting\UselessInheritDocCommentSniff;
use SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullCoalesceOperatorSniff;
use SlevomatCodingStandard\Sniffs\Functions\ArrowFunctionDeclarationSniff;
Expand All @@ -43,22 +37,19 @@
use SlevomatCodingStandard\Sniffs\Namespaces\UseFromSameNamespaceSniff;
use SlevomatCodingStandard\Sniffs\Numbers\RequireNumericLiteralSeparatorSniff;
use SlevomatCodingStandard\Sniffs\PHP\UselessParenthesesSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\UselessConstantTypeHintSniff;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->import(SetList::CLEAN_CODE);
$ecsConfig->import(SetList::PSR_12);
$ecsConfig->import(SetList::COMMON);

$ecsConfig->cacheDirectory(__DIR__ . '/var/ecs_cache');

$ecsConfig->skip([
Configuration::class,
PhpdocTypesOrderFixer::class,
return ECSConfig::configure()
->withPreparedSets(psr12: true, common: true, cleanCode: true)
->withParallel()
->withCache(directory: __DIR__ . '/var/ecs_cache')
->withPaths(paths: [
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSkip([
ArrayListItemNewlineFixer::class => null,
PhpdocToCommentFixer::class => null,
PhpdocAlignFixer::class => null,
Expand All @@ -71,134 +62,76 @@
DoctrineAnnotationBracesFixer::class => null,
NotOperatorWithSuccessorSpaceFixer::class => null,
UselessParenthesesSniff::class => null,
PhpdocSeparationFixer::class => null,
MethodChainingIndentationFixer::class => ['DependencyInjection/*Configuration.php'],
'SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff.DuplicateDeclareStrictTypesSpaces' => null,
OrderedImportsFixer::class => null,
MethodChainingIndentationFixer::class => ['src/DependencyInjection/*Configuration.php'],
'SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff.WriteOnlyProperty' => ['src/Entity/User.php'],
'SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff.DuplicateSpaces' => null,
'SlevomatCodingStandard\Sniffs\Commenting\DisallowCommentAfterCodeSniff.DisallowedCommentAfterCode' => null,
PhpdocAnnotationWithoutDotFixer::class => null,
PhpCsFixer\Fixer\Import\NoUnusedImportsFixer::class => null,
]);

$ecsConfig->extend(
NoSuperfluousPhpdocTagsFixer::class,
function (NoSuperfluousPhpdocTagsFixer $noSuperfluousPhpdocTagsFixer) {
$noSuperfluousPhpdocTagsFixer->configure(['remove_inheritdoc' => false, 'allow_mixed' => false]);

return $noSuperfluousPhpdocTagsFixer;
}
);

$ecsConfig->extend(ClassDefinitionFixer::class, function (ClassDefinitionFixer $classDefinitionFixer) {
$classDefinitionFixer->configure(['multi_line_extends_each_single_line' => false]);

return $classDefinitionFixer;
});

$ecsConfig->extend(
ClassAttributesSeparationFixer::class,
function (ClassAttributesSeparationFixer $classAttributesSeparationFixer) {
$classAttributesSeparationFixer->configure(['elements' => ['method', 'property']]);

return $classAttributesSeparationFixer;
}
);

$ecsConfig->ruleWithConfiguration(DocCommentSpacingSniff::class, [
'annotationsGroups' => [
'@inheritDoc',
'@template, @extends, @implements, @template-implements @template-extends',
'@var, @psalm-var, @param, @psalm-param',
'@return, @psalm-return',
'@throws',
'@psalm-suppress',
],
]);

$ecsConfig->ruleWithConfiguration(UnusedUsesSniff::class, [
'searchAnnotations' => true,
]);

$ecsConfig->ruleWithConfiguration(PropertySpacingSniff::class, [
'minLinesCountBeforeWithComment' => 1,
'maxLinesCountBeforeWithComment' => 1,
'maxLinesCountBeforeWithoutComment' => 0,
]);

$ecsConfig->rule(AlphabeticallySortedUsesSniff::class);
$ecsConfig->rule(StrictCallSniff::class);
$ecsConfig->rule(DeclareStrictTypesFixer::class);
$ecsConfig->rule(MethodSpacingSniff::class);
$ecsConfig->rule(NoNullPropertyInitializationFixer::class);
$ecsConfig->rule(ArrowFunctionDeclarationSniff::class);
$ecsConfig->rule(UseDoesNotStartWithBackslashSniff::class);
$ecsConfig->rule(RequireNumericLiteralSeparatorSniff::class);
$ecsConfig->rule(UselessParenthesesSniff::class);
$ecsConfig->rule(RequireNullCoalesceOperatorSniff::class);
$ecsConfig->rule(ModernClassNameReferenceSniff::class);
$ecsConfig->rule(UselessInheritDocCommentSniff::class);
$ecsConfig->rule(UseFromSameNamespaceSniff::class);
$ecsConfig->rule(UnusedInheritedVariablePassedToClosureSniff::class);
$ecsConfig->rule(UselessConstantTypeHintSniff::class);
$ecsConfig->rule(DoctrineAnnotationArrayAssignmentFixer::class);
$ecsConfig->rule(DoctrineAnnotationIndentationFixer::class);
$ecsConfig->rule(DoctrineAnnotationSpacesFixer::class);
$ecsConfig->rule(BlankLineBeforeStatementFixer::class);

$ecsConfig->ruleWithConfiguration(
YodaStyleFixer::class,
['equal' => true, 'identical' => true, 'less_and_greater' => null]
);

$ecsConfig->ruleWithConfiguration(ForbiddenFunctionsSniff::class, [
'forbiddenFunctions' => [
'chop' => 'rtrim',
'close' => 'closedir',
'delete' => 'unset',
'doubleval' => 'floatval',
'fputs' => 'fwrite',
'imap_create' => 'createmailbox',
'imap_fetchtext' => 'body',
'imap_header' => 'headerinfo',
'imap_listmailbox' => 'list',
'imap_listsubscribed' => 'lsub',
'imap_rename' => 'renamemailbox',
'imap_scan' => 'listscan',
'imap_scanmailbox' => 'listscan',
'mt_rand' => 'random_int',
'ini_alter' => 'set',
'is_double' => 'is_float',
'is_integer' => 'is_int',
'is_null' => '!== null',
'is_real' => 'is_float',
'is_writeable' => 'is_writable',
'join' => 'implode',
'key_exists' => 'array_key_exists',
'magic_quotes_runtime' => 'set_magic_quotes_runtime',
'pos' => 'current',
'rand' => 'random_int',
'show_source' => 'file',
'sizeof' => 'count',
'strchr' => 'strstr',
'create_function' => null,
'call_user_func' => null,
'call_user_func_array' => null,
'forward_static_call' => null,
'forward_static_call_array' => null,
'dump' => null,
'die' => null,
'exit' => null,
'var_dump' => null,
],
]);

$ecsConfig->extend(ArraySyntaxFixer::class, function (ArraySyntaxFixer $arraySyntaxFixer) {
$arraySyntaxFixer->configure(['syntax' => 'short']);

return $arraySyntaxFixer;
});

$ecsConfig->ruleWithConfiguration(ListSyntaxFixer::class, [
'syntax' => 'short',
]);

};
])
->withConfiguredRule(NoSuperfluousPhpdocTagsFixer::class, ['remove_inheritdoc' => false, 'allow_mixed' => false])
->withConfiguredRule(ClassDefinitionFixer::class, ['multi_line_extends_each_single_line' => false])
->withConfiguredRule(ClassAttributesSeparationFixer::class, ['elements' => ['method', 'property']])
->withConfiguredRule(ArraySyntaxFixer::class, ['syntax' => 'short'])
->withConfiguredRule(ListSyntaxFixer::class, ['syntax' => 'short'])
->withConfiguredRule(PropertySpacingSniff::class, ['minLinesCountBeforeWithComment' => 1, 'maxLinesCountBeforeWithComment' => 1, 'maxLinesCountBeforeWithoutComment' => 0])
->withConfiguredRule(UnusedUsesSniff::class, ['searchAnnotations' => true])
->withConfiguredRule(YodaStyleFixer::class, ['identical' => true])
->withConfiguredRule(ForbiddenFunctionsSniff::class, ['forbiddenFunctions' => [
'chop' => 'rtrim',
'close' => 'closedir',
'delete' => 'unset',
'doubleval' => 'floatval',
'fputs' => 'fwrite',
'imap_create' => 'createmailbox',
'imap_fetchtext' => 'body',
'imap_header' => 'headerinfo',
'imap_listmailbox' => 'list',
'imap_listsubscribed' => 'lsub',
'imap_rename' => 'renamemailbox',
'imap_scan' => 'listscan',
'imap_scanmailbox' => 'listscan',
'mt_rand' => 'random_int',
'ini_alter' => 'set',
'is_double' => 'is_float',
'is_integer' => 'is_int',
'is_null' => '!== null',
'is_real' => 'is_float',
'is_writeable' => 'is_writable',
'join' => 'implode',
'key_exists' => 'array_key_exists',
'magic_quotes_runtime' => 'set_magic_quotes_runtime',
'pos' => 'current',
'rand' => 'random_int',
'show_source' => 'file',
'sizeof' => 'count',
'strchr' => 'strstr',
'create_function' => null,
'call_user_func' => null,
'call_user_func_array' => null,
'forward_static_call' => null,
'forward_static_call_array' => null,
'dump' => null,
'die' => null,
'dd' => null,
'echo' => null,
'var_dump' => null,
]])
->withRules([
DeclareStrictTypesFixer::class,
NoNullPropertyInitializationFixer::class,
ArrowFunctionDeclarationSniff::class,
StrictCallSniff::class,
UseDoesNotStartWithBackslashSniff::class,
AlphabeticallySortedUsesSniff::class,
RequireNumericLiteralSeparatorSniff::class,
UselessParenthesesSniff::class,
RequireNullCoalesceOperatorSniff::class,
ModernClassNameReferenceSniff::class,
UselessInheritDocCommentSniff::class,
UseFromSameNamespaceSniff::class,
UnusedInheritedVariablePassedToClosureSniff::class,
DoctrineAnnotationArrayAssignmentFixer::class,
DoctrineAnnotationIndentationFixer::class,
DoctrineAnnotationSpacesFixer::class,
])
;
6 changes: 3 additions & 3 deletions src/Handler/HandlerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

final class HandlerResolver
final readonly class HandlerResolver
{
public function __construct(
private readonly ContainerInterface $handlerLocator,
private readonly array $handlers,
private ContainerInterface $handlerLocator,
private array $handlers,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Handler/Handlers/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use AnzuSystems\SerializerBundle\Helper\SerializerHelper;
use AnzuSystems\SerializerBundle\Metadata\Metadata;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\TypeInfo\TypeIdentifier;

abstract class AbstractHandler implements HandlerInterface
{
Expand Down Expand Up @@ -36,7 +36,7 @@ public function describe(string $property, Metadata $metadata): array
'property' => $property,
'type' => SerializerHelper::getOaFriendlyType($metadata->type),
];
if (Type::BUILTIN_TYPE_FLOAT === $metadata->type) {
if (TypeIdentifier::FLOAT->value === $metadata->type) {
$description['format'] = 'float';
}
if (null === $metadata->setter) {
Expand All @@ -45,7 +45,7 @@ public function describe(string $property, Metadata $metadata): array
if ($metadata->isNullable) {
$description['nullable'] = true;
}
if (Type::BUILTIN_TYPE_ARRAY === $metadata->type) {
if (TypeIdentifier::ARRAY->value === $metadata->type) {
$itemType = [];
if (null !== $metadata->customType && '' !== $metadata->customType) {
$itemType = ['type' => $metadata->customType];
Expand Down
20 changes: 10 additions & 10 deletions src/Handler/Handlers/BasicHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use AnzuSystems\SerializerBundle\Context\SerializationContext;
use AnzuSystems\SerializerBundle\Metadata\Metadata;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\TypeInfo\TypeIdentifier;

final class BasicHandler extends AbstractHandler
{
public const BASIC_TYPES = [
Type::BUILTIN_TYPE_INT,
Type::BUILTIN_TYPE_STRING,
Type::BUILTIN_TYPE_FLOAT,
Type::BUILTIN_TYPE_BOOL,
public const array BASIC_TYPES = [
TypeIdentifier::INT->value,
TypeIdentifier::STRING->value,
TypeIdentifier::FLOAT->value,
TypeIdentifier::BOOL->value,
];

public static function getPriority(): int
Expand Down Expand Up @@ -44,10 +44,10 @@ public function deserialize(mixed $value, Metadata $metadata): string|int|bool|n
}

return match ($metadata->type) {
Type::BUILTIN_TYPE_STRING => (string) $value,
Type::BUILTIN_TYPE_INT => (int) $value,
Type::BUILTIN_TYPE_FLOAT => (float) $value,
Type::BUILTIN_TYPE_BOOL => filter_var($value, FILTER_VALIDATE_BOOL)
TypeIdentifier::STRING->value => (string) $value,
TypeIdentifier::INT->value => (int) $value,
TypeIdentifier::FLOAT->value => (float) $value,
TypeIdentifier::BOOL->value => filter_var($value, FILTER_VALIDATE_BOOL)
};
}

Expand Down
Loading