From 63a31b990ec80f14db27317458c581918c9aaacf Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 17 Oct 2023 11:23:30 +0200 Subject: [PATCH 01/10] Add dataToFormat reject key management --- src/Plugin/Filtering/Builder/Reject.php | 10 +++++++++- src/Plugin/Filtering/Configuration/Reject.php | 7 +++++++ src/Plugin/Filtering/Factory/Reject.php | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index 444ec7ec..d8fb8a45 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -16,6 +16,7 @@ final class Reject implements StepBuilderInterface private ?Node\Expr $logger = null; private ?Node\Expr $rejection = null; private ?Node\Expr $state = null; + private ?Node\Expr $dataToFormat = null; /** @var list */ private array $exclusions = []; @@ -42,6 +43,13 @@ public function withState(Node\Expr $state): self return $this; } + public function withDataToFormat(Node\Expr $dataToFormat): self + { + $this->dataToFormat = $dataToFormat; + + return $this; + } + public function withExclusions(Node\Expr ...$exclusions): self { array_push($this->exclusions, ...$exclusions); @@ -125,7 +133,7 @@ class: new Node\Stmt\Class_(null, [ new Node\Expr\New_( new Node\Name\FullyQualified(RejectionResultBucket::class), [ - new Node\Arg(new Node\Expr\Variable('input')), + $this->dataToFormat !== null ? new Node\Arg($this->dataToFormat) : new Node\Arg(new Node\Expr\Variable('input')) ] ), ), diff --git a/src/Plugin/Filtering/Configuration/Reject.php b/src/Plugin/Filtering/Configuration/Reject.php index 1a426ce2..8752c147 100644 --- a/src/Plugin/Filtering/Configuration/Reject.php +++ b/src/Plugin/Filtering/Configuration/Reject.php @@ -28,6 +28,13 @@ public function getConfigTreeBuilder(): TreeBuilder ->then(asExpression()) ->end() ->end() + ->scalarNode('dataToFormat') + ->cannotBeEmpty() + ->validate() + ->ifTrue(isExpression()) + ->then(asExpression()) + ->end() + ->end() ->end() ->end() ; diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index 047a919f..83c24c4c 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -71,6 +71,9 @@ public function compile(array $config): Repository\Reject $builder->withExclusions( compileExpression($interpreter, $condition['when']) ); + if (array_key_exists('dataToFormat', $condition)) { + $builder->withDataToFormat(compileExpression($interpreter, $condition['dataToFormat'])); + } } return $repository; From 92cb153aa9d389d8a9d8a8ae8158a73046d98895 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 17 Oct 2023 15:29:22 +0200 Subject: [PATCH 02/10] Rename dataToFormat by serialize_rejection --- src/Plugin/Filtering/Builder/Reject.php | 8 ++++---- src/Plugin/Filtering/Configuration/Reject.php | 2 +- src/Plugin/Filtering/Factory/Reject.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index d8fb8a45..b3779a4c 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -16,7 +16,7 @@ final class Reject implements StepBuilderInterface private ?Node\Expr $logger = null; private ?Node\Expr $rejection = null; private ?Node\Expr $state = null; - private ?Node\Expr $dataToFormat = null; + private ?Node\Expr $serialize_rejection = null; /** @var list */ private array $exclusions = []; @@ -43,9 +43,9 @@ public function withState(Node\Expr $state): self return $this; } - public function withDataToFormat(Node\Expr $dataToFormat): self + public function withSerialiazeRejection(Node\Expr $serialize_rejection): self { - $this->dataToFormat = $dataToFormat; + $this->serialize_rejection = $serialize_rejection; return $this; } @@ -133,7 +133,7 @@ class: new Node\Stmt\Class_(null, [ new Node\Expr\New_( new Node\Name\FullyQualified(RejectionResultBucket::class), [ - $this->dataToFormat !== null ? new Node\Arg($this->dataToFormat) : new Node\Arg(new Node\Expr\Variable('input')) + $this->serialize_rejection !== null ? new Node\Arg($this->serialize_rejection) : new Node\Arg(new Node\Expr\Variable('input')) ] ), ), diff --git a/src/Plugin/Filtering/Configuration/Reject.php b/src/Plugin/Filtering/Configuration/Reject.php index 8752c147..ace4c919 100644 --- a/src/Plugin/Filtering/Configuration/Reject.php +++ b/src/Plugin/Filtering/Configuration/Reject.php @@ -28,7 +28,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->then(asExpression()) ->end() ->end() - ->scalarNode('dataToFormat') + ->scalarNode('serialize_rejection') ->cannotBeEmpty() ->validate() ->ifTrue(isExpression()) diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index 83c24c4c..6fc25475 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -71,8 +71,8 @@ public function compile(array $config): Repository\Reject $builder->withExclusions( compileExpression($interpreter, $condition['when']) ); - if (array_key_exists('dataToFormat', $condition)) { - $builder->withDataToFormat(compileExpression($interpreter, $condition['dataToFormat'])); + if (array_key_exists('serialize_rejection', $condition)) { + $builder->withSerialiazeRejection(compileExpression($interpreter, $condition['serialize_rejection'])); } } From 59de5a42fc2a46d5e14f50da1be6dd3e3f627e88 Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 28 Jul 2023 16:55:46 +0200 Subject: [PATCH 03/10] Added reason option into the configuration --- src/Plugin/Filtering/Configuration/Reject.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Plugin/Filtering/Configuration/Reject.php b/src/Plugin/Filtering/Configuration/Reject.php index 1a426ce2..5d085131 100644 --- a/src/Plugin/Filtering/Configuration/Reject.php +++ b/src/Plugin/Filtering/Configuration/Reject.php @@ -28,6 +28,14 @@ public function getConfigTreeBuilder(): TreeBuilder ->then(asExpression()) ->end() ->end() + ->scalarNode('reason') + ->isRequired() + ->cannotBeEmpty() + ->validate() + ->ifTrue(isExpression()) + ->then(asExpression()) + ->end() + ->end() ->end() ->end() ; From c7dab8de814a60941e63bfb45250aa92059190e1 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 20 Oct 2023 10:28:47 +0200 Subject: [PATCH 04/10] use php cs fixer --- .github/workflows/quality.yaml | 2 +- src/Action/Custom/Factory/Action.php | 4 ++-- .../Factory/Repository/RepositoryTrait.php | 2 +- src/Action/Custom/Service.php | 4 ++-- src/Action/SFTP/Factory/Action.php | 6 +++--- .../SFTP/Factory/Repository/Repository.php | 2 +- src/Action/SFTP/Service.php | 4 ++-- src/Adapter/Docker/Satellite.php | 4 ++-- src/Adapter/Docker/SatelliteBuilder.php | 10 +++++----- src/Adapter/Filesystem/Satellite.php | 4 ++-- src/Adapter/Filesystem/SatelliteBuilder.php | 10 +++++----- src/Adapter/Tar/Satellite.php | 4 ++-- src/Adapter/Tar/SatelliteBuilder.php | 10 +++++----- src/Builder/Action.php | 4 ++-- src/Builder/Pipeline.php | 18 +++++++++--------- src/Builder/Repository/API.php | 2 +- src/Builder/Repository/Action.php | 2 +- src/Builder/Repository/Hook.php | 2 +- src/Builder/Repository/Pipeline.php | 2 +- src/Builder/Repository/Workflow.php | 2 +- src/Cloud/Console/Command/CreateCommand.php | 2 +- src/Cloud/Console/Command/RemoveCommand.php | 2 +- src/Cloud/Console/Command/UpdateCommand.php | 2 +- src/Console/Command/BuildCommand.php | 2 +- src/Console/Command/ValidateCommand.php | 2 +- .../Builder/Monolog/ElasticSearchBuilder.php | 2 +- .../Logger/Factory/ElasticSearchFactory.php | 2 +- src/Feature/Logger/Factory/GelfFactory.php | 2 +- src/Feature/Logger/Factory/StreamFactory.php | 2 +- src/Feature/Logger/Factory/SyslogFactory.php | 2 +- src/Feature/Logger/RepositoryTrait.php | 2 +- src/Feature/Logger/Service.php | 4 ++-- .../Rejection/Factory/RabbitMQFactory.php | 2 +- src/Feature/Rejection/RepositoryTrait.php | 2 +- src/Feature/Rejection/Service.php | 4 ++-- src/Feature/State/RepositoryTrait.php | 2 +- src/Feature/State/Service.php | 2 +- src/Interpreter.php | 2 +- src/Plugin/Batching/Repository.php | 6 +++--- src/Plugin/Batching/Service.php | 4 ++-- src/Plugin/Custom/Factory/Extractor.php | 4 ++-- src/Plugin/Custom/Factory/Loader.php | 4 ++-- .../Factory/Repository/RepositoryTrait.php | 2 +- src/Plugin/Custom/Factory/Transformer.php | 4 ++-- src/Plugin/Custom/Service.php | 4 ++-- src/Plugin/FTP/Factory/Loader.php | 6 +++--- .../FTP/Factory/Repository/Repository.php | 2 +- src/Plugin/FTP/Factory/Server.php | 6 +++--- src/Plugin/FTP/Service.php | 4 ++-- src/Plugin/Filtering/Builder/Reject.php | 2 +- src/Plugin/Filtering/Factory/Drop.php | 4 ++-- src/Plugin/Filtering/Factory/Reject.php | 6 +++--- .../Factory/Repository/RepositoryTrait.php | 2 +- src/Plugin/Filtering/Service.php | 4 ++-- src/Plugin/SFTP/Factory/Extractor.php | 6 +++--- src/Plugin/SFTP/Factory/Loader.php | 6 +++--- .../SFTP/Factory/Repository/Repository.php | 2 +- src/Plugin/SFTP/Factory/Server.php | 6 +++--- src/Plugin/SFTP/Service.php | 4 ++-- src/Plugin/Stream/Repository.php | 6 +++--- src/Plugin/Stream/Service.php | 4 ++-- src/Service.php | 6 +++--- 62 files changed, 121 insertions(+), 121 deletions(-) diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 81e014bd..75470482 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -14,7 +14,7 @@ jobs: run: | wget -q https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer chmod a+x php-cs-fixer - PHP_CS_FIXER_IGNORE_ENV=true ./php-cs-fixer fix src --dry-run + ./php-cs-fixer fix src --dry-run phpstan: runs-on: ubuntu-latest diff --git a/src/Action/Custom/Factory/Action.php b/src/Action/Custom/Factory/Action.php index 29279a9c..eb70c1ec 100644 --- a/src/Action/Custom/Factory/Action.php +++ b/src/Action/Custom/Factory/Action.php @@ -44,7 +44,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -55,7 +55,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Action/Custom/Factory/Repository/RepositoryTrait.php b/src/Action/Custom/Factory/Repository/RepositoryTrait.php index 200ef6c0..447d6fa4 100644 --- a/src/Action/Custom/Factory/Repository/RepositoryTrait.php +++ b/src/Action/Custom/Factory/Repository/RepositoryTrait.php @@ -14,7 +14,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Action/Custom/Service.php b/src/Action/Custom/Service.php index be6c7550..4bd351ca 100644 --- a/src/Action/Custom/Service.php +++ b/src/Action/Custom/Service.php @@ -43,7 +43,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -54,7 +54,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Action/SFTP/Factory/Action.php b/src/Action/SFTP/Factory/Action.php index 03a51221..968853a7 100644 --- a/src/Action/SFTP/Factory/Action.php +++ b/src/Action/SFTP/Factory/Action.php @@ -39,7 +39,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -50,7 +50,7 @@ public function validate(array $config): bool $this->normalize($config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -68,7 +68,7 @@ public function compile(array $config): Repository try { return new Repository($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Action/SFTP/Factory/Repository/Repository.php b/src/Action/SFTP/Factory/Repository/Repository.php index 278c67dd..30614486 100644 --- a/src/Action/SFTP/Factory/Repository/Repository.php +++ b/src/Action/SFTP/Factory/Repository/Repository.php @@ -12,7 +12,7 @@ { public function __construct(private Builder\Action $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { return $this; } diff --git a/src/Action/SFTP/Service.php b/src/Action/SFTP/Service.php index 9255277d..53385fa1 100644 --- a/src/Action/SFTP/Service.php +++ b/src/Action/SFTP/Service.php @@ -45,7 +45,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -56,7 +56,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Adapter/Docker/Satellite.php b/src/Adapter/Docker/Satellite.php index e5742f2a..fd34801a 100644 --- a/src/Adapter/Docker/Satellite.php +++ b/src/Adapter/Docker/Satellite.php @@ -22,7 +22,7 @@ final class Satellite implements Configurator\SatelliteInterface public function __construct( private readonly Dockerfile\Dockerfile $dockerfile, private readonly string $workdir, - Packaging\FileInterface|Packaging\DirectoryInterface ...$files + Packaging\DirectoryInterface|Packaging\FileInterface ...$files ) { $this->files = $files; } @@ -34,7 +34,7 @@ public function addTags(string ...$imageTags): self return $this; } - public function withFile(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function withFile(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { array_push($this->files, ...$files); diff --git a/src/Adapter/Docker/SatelliteBuilder.php b/src/Adapter/Docker/SatelliteBuilder.php index a5b71496..1ad2594c 100644 --- a/src/Adapter/Docker/SatelliteBuilder.php +++ b/src/Adapter/Docker/SatelliteBuilder.php @@ -23,8 +23,8 @@ final class SatelliteBuilder implements Configurator\SatelliteBuilderInterface private iterable $command = []; /** @var iterable */ private iterable $tags = []; - private null|PackagingContract\FileInterface|PackagingContract\AssetInterface $composerJsonFile = null; - private null|PackagingContract\FileInterface|PackagingContract\AssetInterface $composerLockFile = null; + private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile = null; + private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null; /** @var iterable> */ private iterable $paths = []; /** @var \AppendIterator> */ @@ -66,8 +66,8 @@ public function withComposerRequire(string ...$package): self } public function withComposerFile( - PackagingContract\FileInterface|PackagingContract\AssetInterface $composerJsonFile, - PackagingContract\FileInterface|PackagingContract\AssetInterface $composerLockFile = null + PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile, + PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null ): self { $this->composerJsonFile = $composerJsonFile; $this->composerLockFile = $composerLockFile; @@ -76,7 +76,7 @@ public function withComposerFile( } public function withFile( - PackagingContract\FileInterface|PackagingContract\AssetInterface $source, + PackagingContract\AssetInterface|PackagingContract\FileInterface $source, string $destinationPath = null ): self { if (!$source instanceof PackagingContract\FileInterface) { diff --git a/src/Adapter/Filesystem/Satellite.php b/src/Adapter/Filesystem/Satellite.php index 092aaadb..d8edbc01 100644 --- a/src/Adapter/Filesystem/Satellite.php +++ b/src/Adapter/Filesystem/Satellite.php @@ -18,12 +18,12 @@ final class Satellite implements Configurator\SatelliteInterface public function __construct( private readonly string $workdir, private readonly Composer $composer, - Packaging\FileInterface|Packaging\DirectoryInterface ...$files + Packaging\DirectoryInterface|Packaging\FileInterface ...$files ) { $this->files = $files; } - public function withFile(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function withFile(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { array_push($this->files, ...$files); diff --git a/src/Adapter/Filesystem/SatelliteBuilder.php b/src/Adapter/Filesystem/SatelliteBuilder.php index a7ce0409..1a400c38 100644 --- a/src/Adapter/Filesystem/SatelliteBuilder.php +++ b/src/Adapter/Filesystem/SatelliteBuilder.php @@ -20,8 +20,8 @@ final class SatelliteBuilder implements Configurator\SatelliteBuilderInterface ]; private array $authenticationTokens = []; private array $repositories = []; - private null|PackagingContract\FileInterface|PackagingContract\AssetInterface $composerJsonFile = null; - private null|PackagingContract\FileInterface|PackagingContract\AssetInterface $composerLockFile = null; + private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile = null; + private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null; /** @var iterable> */ private iterable $paths = []; /** @var \AppendIterator> */ @@ -54,8 +54,8 @@ public function withComposerRequire(string ...$package): self } public function withComposerFile( - PackagingContract\FileInterface|PackagingContract\AssetInterface $composerJsonFile, - PackagingContract\FileInterface|PackagingContract\AssetInterface $composerLockFile = null + PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile, + PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null ): self { $this->composerJsonFile = $composerJsonFile; $this->composerLockFile = $composerLockFile; @@ -64,7 +64,7 @@ public function withComposerFile( } public function withFile( - PackagingContract\FileInterface|PackagingContract\AssetInterface $source, + PackagingContract\AssetInterface|PackagingContract\FileInterface $source, string $destinationPath = null ): self { if (!$source instanceof PackagingContract\FileInterface) { diff --git a/src/Adapter/Tar/Satellite.php b/src/Adapter/Tar/Satellite.php index e80c81b9..2eb47e88 100644 --- a/src/Adapter/Tar/Satellite.php +++ b/src/Adapter/Tar/Satellite.php @@ -19,7 +19,7 @@ final class Satellite implements Configurator\SatelliteInterface public function __construct( private readonly string $outputPath, - Packaging\FileInterface|Packaging\DirectoryInterface ...$files + Packaging\DirectoryInterface|Packaging\FileInterface ...$files ) { $this->files = $files; } @@ -31,7 +31,7 @@ public function addTags(string ...$imageTags): self return $this; } - public function withFile(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function withFile(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { array_push($this->files, ...$files); diff --git a/src/Adapter/Tar/SatelliteBuilder.php b/src/Adapter/Tar/SatelliteBuilder.php index c65ac1c7..68c89afd 100644 --- a/src/Adapter/Tar/SatelliteBuilder.php +++ b/src/Adapter/Tar/SatelliteBuilder.php @@ -13,8 +13,8 @@ final class SatelliteBuilder implements Configurator\SatelliteBuilderInterface { /** @var iterable */ private iterable $composerRequire = []; - private null|PackagingContract\FileInterface|PackagingContract\AssetInterface $composerJsonFile = null; - private null|PackagingContract\FileInterface|PackagingContract\AssetInterface $composerLockFile = null; + private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile = null; + private null|PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null; /** @var \AppendIterator> */ private readonly iterable $files; /** @var array> */ @@ -47,8 +47,8 @@ public function withComposerRequire(string ...$package): self } public function withComposerFile( - PackagingContract\FileInterface|PackagingContract\AssetInterface $composerJsonFile, - PackagingContract\FileInterface|PackagingContract\AssetInterface $composerLockFile = null + PackagingContract\AssetInterface|PackagingContract\FileInterface $composerJsonFile, + PackagingContract\AssetInterface|PackagingContract\FileInterface $composerLockFile = null ): self { $this->composerJsonFile = $composerJsonFile; $this->composerLockFile = $composerLockFile; @@ -57,7 +57,7 @@ public function withComposerFile( } public function withFile( - PackagingContract\FileInterface|PackagingContract\AssetInterface $source, + PackagingContract\AssetInterface|PackagingContract\FileInterface $source, string $destinationPath = null ): self { if (!$source instanceof PackagingContract\FileInterface) { diff --git a/src/Builder/Action.php b/src/Builder/Action.php index fea89225..3bcc2282 100644 --- a/src/Builder/Action.php +++ b/src/Builder/Action.php @@ -16,8 +16,8 @@ public function __construct( ) {} public function addAction( - Node\Expr|Builder $loader, - Node\Expr|Builder $state, + Builder|Node\Expr $loader, + Builder|Node\Expr $state, ): self { $this->action = new Node\Expr\MethodCall( var: $this->runtime, diff --git a/src/Builder/Pipeline.php b/src/Builder/Pipeline.php index 80aa8c8c..2c6a3eb1 100644 --- a/src/Builder/Pipeline.php +++ b/src/Builder/Pipeline.php @@ -16,9 +16,9 @@ public function __construct( ) {} public function addExtractor( - Node\Expr|Builder $extractor, - Node\Expr|Builder $rejection, - Node\Expr|Builder $state, + Builder|Node\Expr $extractor, + Builder|Node\Expr $rejection, + Builder|Node\Expr $state, ): self { $this->steps[] = fn (Node\Expr $runtime) => new Node\Expr\MethodCall( var: $runtime, @@ -34,9 +34,9 @@ public function addExtractor( } public function addTransformer( - Node\Expr|Builder $transformer, - Node\Expr|Builder $rejection, - Node\Expr|Builder $state, + Builder|Node\Expr $transformer, + Builder|Node\Expr $rejection, + Builder|Node\Expr $state, ): self { $this->steps[] = fn (Node\Expr $runtime) => new Node\Expr\MethodCall( var: $runtime, @@ -52,9 +52,9 @@ public function addTransformer( } public function addLoader( - Node\Expr|Builder $loader, - Node\Expr|Builder $rejection, - Node\Expr|Builder $state, + Builder|Node\Expr $loader, + Builder|Node\Expr $rejection, + Builder|Node\Expr $state, ): self { $this->steps[] = fn (Node\Expr $runtime) => new Node\Expr\MethodCall( var: $runtime, diff --git a/src/Builder/Repository/API.php b/src/Builder/Repository/API.php index 6f084207..ec96aca5 100644 --- a/src/Builder/Repository/API.php +++ b/src/Builder/Repository/API.php @@ -17,7 +17,7 @@ final class API implements Configurator\RepositoryInterface public function __construct(private readonly Satellite\Builder\API $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Builder/Repository/Action.php b/src/Builder/Repository/Action.php index 807566ea..be8a0e73 100644 --- a/src/Builder/Repository/Action.php +++ b/src/Builder/Repository/Action.php @@ -17,7 +17,7 @@ final class Action implements Configurator\RepositoryInterface public function __construct(private readonly Satellite\Builder\Action $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Builder/Repository/Hook.php b/src/Builder/Repository/Hook.php index 849f88a6..d7d56b3a 100644 --- a/src/Builder/Repository/Hook.php +++ b/src/Builder/Repository/Hook.php @@ -17,7 +17,7 @@ final class Hook implements Configurator\RepositoryInterface public function __construct(private readonly Satellite\Builder\Hook $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Builder/Repository/Pipeline.php b/src/Builder/Repository/Pipeline.php index ac171e2d..2d82a798 100644 --- a/src/Builder/Repository/Pipeline.php +++ b/src/Builder/Repository/Pipeline.php @@ -17,7 +17,7 @@ final class Pipeline implements Configurator\RepositoryInterface public function __construct(private readonly Satellite\Builder\Pipeline $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Builder/Repository/Workflow.php b/src/Builder/Repository/Workflow.php index 23aac5b6..f4516fe6 100644 --- a/src/Builder/Repository/Workflow.php +++ b/src/Builder/Repository/Workflow.php @@ -17,7 +17,7 @@ final class Workflow implements Configurator\RepositoryInterface public function __construct(private readonly Satellite\Builder\Workflow $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index 834c6ae9..c3446ba4 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -82,7 +82,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O try { $configuration = $service->normalize($configuration); - } catch (Config\Definition\Exception\InvalidTypeException|Config\Definition\Exception\InvalidConfigurationException $exception) { + } catch (Config\Definition\Exception\InvalidConfigurationException|Config\Definition\Exception\InvalidTypeException $exception) { $style->error($exception->getMessage()); return self::FAILURE; diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 6608d1f8..f48e1ae7 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -82,7 +82,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O try { $configuration = $service->normalize($configuration); - } catch (Config\Definition\Exception\InvalidTypeException|Config\Definition\Exception\InvalidConfigurationException $exception) { + } catch (Config\Definition\Exception\InvalidConfigurationException|Config\Definition\Exception\InvalidTypeException $exception) { $style->error($exception->getMessage()); return self::FAILURE; diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 4fcd5e77..7fb93962 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -82,7 +82,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O try { $configuration = $service->normalize($configuration); - } catch (Config\Definition\Exception\InvalidTypeException|Config\Definition\Exception\InvalidConfigurationException $exception) { + } catch (Config\Definition\Exception\InvalidConfigurationException|Config\Definition\Exception\InvalidTypeException $exception) { $style->error($exception->getMessage()); return self::FAILURE; diff --git a/src/Console/Command/BuildCommand.php b/src/Console/Command/BuildCommand.php index 5e6ad29c..2d1487b9 100644 --- a/src/Console/Command/BuildCommand.php +++ b/src/Console/Command/BuildCommand.php @@ -67,7 +67,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O try { $configuration = $service->normalize($configuration); - } catch (Config\Definition\Exception\InvalidTypeException|Config\Definition\Exception\InvalidConfigurationException $exception) { + } catch (Config\Definition\Exception\InvalidConfigurationException|Config\Definition\Exception\InvalidTypeException $exception) { $style->error($exception->getMessage()); return 255; diff --git a/src/Console/Command/ValidateCommand.php b/src/Console/Command/ValidateCommand.php index e342d78c..2ae8db02 100644 --- a/src/Console/Command/ValidateCommand.php +++ b/src/Console/Command/ValidateCommand.php @@ -66,7 +66,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O try { $configuration = $service->normalize($configuration); - } catch (Config\Definition\Exception\InvalidTypeException|Config\Definition\Exception\InvalidConfigurationException $exception) { + } catch (Config\Definition\Exception\InvalidConfigurationException|Config\Definition\Exception\InvalidTypeException $exception) { $style->error($exception->getMessage()); return 255; diff --git a/src/Feature/Logger/Builder/Monolog/ElasticSearchBuilder.php b/src/Feature/Logger/Builder/Monolog/ElasticSearchBuilder.php index 1bb4018a..be01985f 100644 --- a/src/Feature/Logger/Builder/Monolog/ElasticSearchBuilder.php +++ b/src/Feature/Logger/Builder/Monolog/ElasticSearchBuilder.php @@ -34,7 +34,7 @@ public function withIndex(string $index): self return $this; } - public function withHosts(string|array|Expression ...$hosts): self + public function withHosts(array|Expression|string ...$hosts): self { array_push($this->hosts, ...$hosts); diff --git a/src/Feature/Logger/Factory/ElasticSearchFactory.php b/src/Feature/Logger/Factory/ElasticSearchFactory.php index 366bdcf0..7e265448 100644 --- a/src/Feature/Logger/Factory/ElasticSearchFactory.php +++ b/src/Feature/Logger/Factory/ElasticSearchFactory.php @@ -36,7 +36,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } diff --git a/src/Feature/Logger/Factory/GelfFactory.php b/src/Feature/Logger/Factory/GelfFactory.php index 132872ef..c7017afe 100644 --- a/src/Feature/Logger/Factory/GelfFactory.php +++ b/src/Feature/Logger/Factory/GelfFactory.php @@ -33,7 +33,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } diff --git a/src/Feature/Logger/Factory/StreamFactory.php b/src/Feature/Logger/Factory/StreamFactory.php index 2886bac7..0048058d 100644 --- a/src/Feature/Logger/Factory/StreamFactory.php +++ b/src/Feature/Logger/Factory/StreamFactory.php @@ -33,7 +33,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } diff --git a/src/Feature/Logger/Factory/SyslogFactory.php b/src/Feature/Logger/Factory/SyslogFactory.php index 7bf4b8f5..9d2ad46c 100644 --- a/src/Feature/Logger/Factory/SyslogFactory.php +++ b/src/Feature/Logger/Factory/SyslogFactory.php @@ -33,7 +33,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } diff --git a/src/Feature/Logger/RepositoryTrait.php b/src/Feature/Logger/RepositoryTrait.php index ed522a90..f2d6ae88 100644 --- a/src/Feature/Logger/RepositoryTrait.php +++ b/src/Feature/Logger/RepositoryTrait.php @@ -14,7 +14,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { array_push($this->files, ...$files); diff --git a/src/Feature/Logger/Service.php b/src/Feature/Logger/Service.php index 7e1af794..9de85707 100644 --- a/src/Feature/Logger/Service.php +++ b/src/Feature/Logger/Service.php @@ -42,7 +42,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -158,7 +158,7 @@ public function compile(array $config): Repository $builder->withLogger($monologBuilder->getNode()); return $repository; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Feature/Rejection/Factory/RabbitMQFactory.php b/src/Feature/Rejection/Factory/RabbitMQFactory.php index 2f785ba9..7de68b4f 100644 --- a/src/Feature/Rejection/Factory/RabbitMQFactory.php +++ b/src/Feature/Rejection/Factory/RabbitMQFactory.php @@ -38,7 +38,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } diff --git a/src/Feature/Rejection/RepositoryTrait.php b/src/Feature/Rejection/RepositoryTrait.php index c0545d79..118dc131 100644 --- a/src/Feature/Rejection/RepositoryTrait.php +++ b/src/Feature/Rejection/RepositoryTrait.php @@ -14,7 +14,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { array_push($this->files, ...$files); diff --git a/src/Feature/Rejection/Service.php b/src/Feature/Rejection/Service.php index 9a10e741..3296a24a 100644 --- a/src/Feature/Rejection/Service.php +++ b/src/Feature/Rejection/Service.php @@ -41,7 +41,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -82,7 +82,7 @@ public function compile(array $config): Repository } return $repository; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Feature/State/RepositoryTrait.php b/src/Feature/State/RepositoryTrait.php index 1d0943d6..c2f89736 100644 --- a/src/Feature/State/RepositoryTrait.php +++ b/src/Feature/State/RepositoryTrait.php @@ -14,7 +14,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { array_push($this->files, ...$files); diff --git a/src/Feature/State/Service.php b/src/Feature/State/Service.php index 72720cba..7b6cf1b5 100644 --- a/src/Feature/State/Service.php +++ b/src/Feature/State/Service.php @@ -41,7 +41,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } diff --git a/src/Interpreter.php b/src/Interpreter.php index 1b98d7f5..87221bfb 100644 --- a/src/Interpreter.php +++ b/src/Interpreter.php @@ -14,7 +14,7 @@ final class Interpreter private readonly array $expressionFunctions; public function __construct( - ExpressionFunctionProviderInterface|ExpressionFunction ...$expressionFunctions + ExpressionFunction|ExpressionFunctionProviderInterface ...$expressionFunctions ) { $this->expressionFunctions = $expressionFunctions; } diff --git a/src/Plugin/Batching/Repository.php b/src/Plugin/Batching/Repository.php index 23dd6c42..cb4d4e14 100644 --- a/src/Plugin/Batching/Repository.php +++ b/src/Plugin/Batching/Repository.php @@ -11,9 +11,9 @@ final readonly class Repository implements Configurator\StepRepositoryInterface { - public function __construct(private Merge|Fork $builder) {} + public function __construct(private Fork|Merge $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { return $this; } @@ -33,7 +33,7 @@ public function getPackages(): iterable return new \EmptyIterator(); } - public function getBuilder(): Merge|Fork + public function getBuilder(): Fork|Merge { return $this->builder; } diff --git a/src/Plugin/Batching/Service.php b/src/Plugin/Batching/Service.php index 9bf76aab..d3204bb9 100644 --- a/src/Plugin/Batching/Service.php +++ b/src/Plugin/Batching/Service.php @@ -55,7 +55,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -66,7 +66,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Custom/Factory/Extractor.php b/src/Plugin/Custom/Factory/Extractor.php index ccf1088d..5690023d 100644 --- a/src/Plugin/Custom/Factory/Extractor.php +++ b/src/Plugin/Custom/Factory/Extractor.php @@ -44,7 +44,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -55,7 +55,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Custom/Factory/Loader.php b/src/Plugin/Custom/Factory/Loader.php index aed11d17..69a17a52 100644 --- a/src/Plugin/Custom/Factory/Loader.php +++ b/src/Plugin/Custom/Factory/Loader.php @@ -44,7 +44,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -55,7 +55,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Custom/Factory/Repository/RepositoryTrait.php b/src/Plugin/Custom/Factory/Repository/RepositoryTrait.php index c8a7b63b..fb9a52a6 100644 --- a/src/Plugin/Custom/Factory/Repository/RepositoryTrait.php +++ b/src/Plugin/Custom/Factory/Repository/RepositoryTrait.php @@ -14,7 +14,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Plugin/Custom/Factory/Transformer.php b/src/Plugin/Custom/Factory/Transformer.php index 23a99803..5beb12e3 100644 --- a/src/Plugin/Custom/Factory/Transformer.php +++ b/src/Plugin/Custom/Factory/Transformer.php @@ -44,7 +44,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -55,7 +55,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Custom/Service.php b/src/Plugin/Custom/Service.php index 69a862dd..0818a8e4 100644 --- a/src/Plugin/Custom/Service.php +++ b/src/Plugin/Custom/Service.php @@ -47,7 +47,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -58,7 +58,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/FTP/Factory/Loader.php b/src/Plugin/FTP/Factory/Loader.php index 0e501b8c..f9caa4a7 100644 --- a/src/Plugin/FTP/Factory/Loader.php +++ b/src/Plugin/FTP/Factory/Loader.php @@ -39,7 +39,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -50,7 +50,7 @@ public function validate(array $config): bool $this->normalize($config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -88,7 +88,7 @@ public function compile(array $config): RepositoryInterface try { return new FTP\Factory\Repository\Repository($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Plugin/FTP/Factory/Repository/Repository.php b/src/Plugin/FTP/Factory/Repository/Repository.php index 240170e9..81b74abf 100644 --- a/src/Plugin/FTP/Factory/Repository/Repository.php +++ b/src/Plugin/FTP/Factory/Repository/Repository.php @@ -12,7 +12,7 @@ { public function __construct(private Builder\Loader|Builder\Server $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { return $this; } diff --git a/src/Plugin/FTP/Factory/Server.php b/src/Plugin/FTP/Factory/Server.php index 28530ff6..8bd71dd2 100644 --- a/src/Plugin/FTP/Factory/Server.php +++ b/src/Plugin/FTP/Factory/Server.php @@ -38,7 +38,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -49,7 +49,7 @@ public function validate(array $config): bool $this->normalize($config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -75,7 +75,7 @@ public function compile(array $config): FTP\Factory\Repository\Repository try { return new FTP\Factory\Repository\Repository($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Plugin/FTP/Service.php b/src/Plugin/FTP/Service.php index 33a816de..da93e63e 100644 --- a/src/Plugin/FTP/Service.php +++ b/src/Plugin/FTP/Service.php @@ -45,7 +45,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -56,7 +56,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index b3779a4c..a84ded29 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -133,7 +133,7 @@ class: new Node\Stmt\Class_(null, [ new Node\Expr\New_( new Node\Name\FullyQualified(RejectionResultBucket::class), [ - $this->serialize_rejection !== null ? new Node\Arg($this->serialize_rejection) : new Node\Arg(new Node\Expr\Variable('input')) + null !== $this->serialize_rejection ? new Node\Arg($this->serialize_rejection) : new Node\Arg(new Node\Expr\Variable('input')), ] ), ), diff --git a/src/Plugin/Filtering/Factory/Drop.php b/src/Plugin/Filtering/Factory/Drop.php index 5236e40a..0736b536 100644 --- a/src/Plugin/Filtering/Factory/Drop.php +++ b/src/Plugin/Filtering/Factory/Drop.php @@ -40,7 +40,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -51,7 +51,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index 6fc25475..d809c5b5 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -40,7 +40,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -51,7 +51,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -71,7 +71,7 @@ public function compile(array $config): Repository\Reject $builder->withExclusions( compileExpression($interpreter, $condition['when']) ); - if (array_key_exists('serialize_rejection', $condition)) { + if (\array_key_exists('serialize_rejection', $condition)) { $builder->withSerialiazeRejection(compileExpression($interpreter, $condition['serialize_rejection'])); } } diff --git a/src/Plugin/Filtering/Factory/Repository/RepositoryTrait.php b/src/Plugin/Filtering/Factory/Repository/RepositoryTrait.php index f332d595..1457f00d 100644 --- a/src/Plugin/Filtering/Factory/Repository/RepositoryTrait.php +++ b/src/Plugin/Filtering/Factory/Repository/RepositoryTrait.php @@ -14,7 +14,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Plugin/Filtering/Service.php b/src/Plugin/Filtering/Service.php index f63c4021..8c04104b 100644 --- a/src/Plugin/Filtering/Service.php +++ b/src/Plugin/Filtering/Service.php @@ -46,7 +46,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -57,7 +57,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/SFTP/Factory/Extractor.php b/src/Plugin/SFTP/Factory/Extractor.php index 014eb4e9..dc4e97ed 100644 --- a/src/Plugin/SFTP/Factory/Extractor.php +++ b/src/Plugin/SFTP/Factory/Extractor.php @@ -39,7 +39,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -50,7 +50,7 @@ public function validate(array $config): bool $this->normalize($config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -87,7 +87,7 @@ public function compile(array $config): Repository try { return new Repository($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Plugin/SFTP/Factory/Loader.php b/src/Plugin/SFTP/Factory/Loader.php index 1213dcee..e24b3611 100644 --- a/src/Plugin/SFTP/Factory/Loader.php +++ b/src/Plugin/SFTP/Factory/Loader.php @@ -39,7 +39,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -50,7 +50,7 @@ public function validate(array $config): bool $this->normalize($config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -87,7 +87,7 @@ public function compile(array $config): Repository try { return new Repository($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Plugin/SFTP/Factory/Repository/Repository.php b/src/Plugin/SFTP/Factory/Repository/Repository.php index 8ed17a76..d6277f17 100644 --- a/src/Plugin/SFTP/Factory/Repository/Repository.php +++ b/src/Plugin/SFTP/Factory/Repository/Repository.php @@ -12,7 +12,7 @@ { public function __construct(private Builder\Loader|Builder\Server $builder) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { return $this; } diff --git a/src/Plugin/SFTP/Factory/Server.php b/src/Plugin/SFTP/Factory/Server.php index 62e498fa..1a2f7d02 100644 --- a/src/Plugin/SFTP/Factory/Server.php +++ b/src/Plugin/SFTP/Factory/Server.php @@ -38,7 +38,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -49,7 +49,7 @@ public function validate(array $config): bool $this->normalize($config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -84,7 +84,7 @@ public function compile(array $config): SFTP\Factory\Repository\Repository try { return new SFTP\Factory\Repository\Repository($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Plugin/SFTP/Service.php b/src/Plugin/SFTP/Service.php index ba5992c5..e0ae7a85 100644 --- a/src/Plugin/SFTP/Service.php +++ b/src/Plugin/SFTP/Service.php @@ -46,7 +46,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -57,7 +57,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Plugin/Stream/Repository.php b/src/Plugin/Stream/Repository.php index 79bb0dff..c2f9b53c 100644 --- a/src/Plugin/Stream/Repository.php +++ b/src/Plugin/Stream/Repository.php @@ -10,10 +10,10 @@ final readonly class Repository implements Configurator\StepRepositoryInterface { public function __construct( - private Builder\StderrLoader|Builder\StdoutLoader|Builder\JSONStreamLoader|Builder\DebugLoader $builder + private Builder\DebugLoader|Builder\JSONStreamLoader|Builder\StderrLoader|Builder\StdoutLoader $builder ) {} - public function addFiles(Packaging\FileInterface|Packaging\DirectoryInterface ...$files): self + public function addFiles(Packaging\DirectoryInterface|Packaging\FileInterface ...$files): self { return $this; } @@ -33,7 +33,7 @@ public function getPackages(): iterable return new \EmptyIterator(); } - public function getBuilder(): Builder\StderrLoader|Builder\StdoutLoader|Builder\JSONStreamLoader|Builder\DebugLoader + public function getBuilder(): Builder\DebugLoader|Builder\JSONStreamLoader|Builder\StderrLoader|Builder\StdoutLoader { return $this->builder; } diff --git a/src/Plugin/Stream/Service.php b/src/Plugin/Stream/Service.php index 3f3e11a9..c1fba50c 100644 --- a/src/Plugin/Stream/Service.php +++ b/src/Plugin/Stream/Service.php @@ -45,7 +45,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -56,7 +56,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } diff --git a/src/Service.php b/src/Service.php index e55a0ca8..079ddec4 100644 --- a/src/Service.php +++ b/src/Service.php @@ -147,7 +147,7 @@ public function registerRuntimes(Satellite\Runtime\FactoryInterface ...$runtimes return $this; } - public function registerPlugins(Configurator\PipelinePluginInterface|Configurator\PipelineFeatureInterface ...$plugins): self + public function registerPlugins(Configurator\PipelineFeatureInterface|Configurator\PipelinePluginInterface ...$plugins): self { foreach ($plugins as $plugin) { /** @var Configurator\Feature $attribute */ @@ -188,7 +188,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -199,7 +199,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } From d58d507a1e1b1a595b1d26520fc76eb7c1acb03c Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 20 Oct 2023 15:57:03 +0200 Subject: [PATCH 05/10] Added a way to add reason rejection in the filtering plugin configuration --- src/Plugin/Filtering/Builder/Reject.php | 95 +++++++------------ src/Plugin/Filtering/Configuration/Reject.php | 2 - src/Plugin/Filtering/DTO/Exclusion.php | 15 +++ src/Plugin/Filtering/Factory/Reject.php | 6 +- 4 files changed, 54 insertions(+), 64 deletions(-) create mode 100644 src/Plugin/Filtering/DTO/Exclusion.php diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index 444ec7ec..912d030a 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -6,6 +6,8 @@ use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\RejectionResultBucket; +use Kiboko\Component\Bucket\RejectionWithReasonResultBucket; +use Kiboko\Component\Satellite\Plugin\Filtering\DTO\Exclusion; use Kiboko\Contract\Configurator\StepBuilderInterface; use Kiboko\Contract\Pipeline\TransformerInterface; use PhpParser\Builder; @@ -16,11 +18,9 @@ final class Reject implements StepBuilderInterface private ?Node\Expr $logger = null; private ?Node\Expr $rejection = null; private ?Node\Expr $state = null; - /** @var list */ + /** @var list */ private array $exclusions = []; - public function __construct() {} - public function withLogger(Node\Expr $logger): self { $this->logger = $logger; @@ -42,53 +42,46 @@ public function withState(Node\Expr $state): self return $this; } - public function withExclusions(Node\Expr ...$exclusions): self + public function withExclusions(Exclusion ...$exclusions): self { array_push($this->exclusions, ...$exclusions); return $this; } - private function buildExclusions(Node\Expr ...$exclusions): Node\Expr + private function buildExclusions(Exclusion ...$exclusions): array { - if (\count($exclusions) > 3) { - $length = \count($exclusions); - $middle = (int) floor($length / 2); - $left = \array_slice($exclusions, 0, $middle); - $right = \array_slice($exclusions, $middle, $length); - - return new Node\Expr\BinaryOp\BooleanAnd( - $this->buildExclusions(...$left), - $this->buildExclusions(...$right), - ); - } - - if (\count($exclusions) > 2) { - $right = array_shift($exclusions); - - return new Node\Expr\BinaryOp\BooleanAnd( - $this->buildExclusions(...$exclusions), - $right, - ); - } - - if (\count($exclusions) > 1) { - $left = array_pop($exclusions); - $right = array_pop($exclusions); - - return new Node\Expr\BinaryOp\BooleanAnd( - $left, - $right, + $statements = []; + foreach ($exclusions as $exclusion) { + $statements[] = new Node\Stmt\If_( + $exclusion->when, + [ + 'stmts' => [ + new Node\Stmt\Expression( + new Node\Expr\Assign( + new Node\Expr\Variable('input'), + new Node\Expr\Yield_( + new Node\Expr\New_( + $exclusion->reason ? new Node\Name\FullyQualified(RejectionWithReasonResultBucket::class) : new Node\Name\FullyQualified(RejectionResultBucket::class), + [ + new Node\Arg(new Node\Expr\Variable('input')), + $exclusion->reason ? new Node\Arg($exclusion->reason) : new Node\Arg( + new Node\Expr\ConstFetch( + new Node\Name(null) + ), + ), + ] + ), + ), + ), + ), + new Node\Stmt\Continue_(), + ], + ] ); } - if (\count($exclusions) > 0) { - return array_pop($exclusions); - } - - return new Node\Expr\ConstFetch( - new Node\Name('false'), - ); + return $statements; } public function getNode(): Node @@ -114,27 +107,7 @@ class: new Node\Stmt\Class_(null, [ new Node\Name('true'), ), [ - new Node\Stmt\If_( - $this->buildExclusions(...$this->exclusions), - [ - 'stmts' => [ - new Node\Stmt\Expression( - new Node\Expr\Assign( - new Node\Expr\Variable('input'), - new Node\Expr\Yield_( - new Node\Expr\New_( - new Node\Name\FullyQualified(RejectionResultBucket::class), - [ - new Node\Arg(new Node\Expr\Variable('input')), - ] - ), - ), - ), - ), - new Node\Stmt\Continue_(), - ], - ] - ), + ...$this->buildExclusions(...$this->exclusions), new Node\Stmt\Expression( new Node\Expr\Assign( new Node\Expr\Variable('input'), diff --git a/src/Plugin/Filtering/Configuration/Reject.php b/src/Plugin/Filtering/Configuration/Reject.php index 5d085131..c52061a8 100644 --- a/src/Plugin/Filtering/Configuration/Reject.php +++ b/src/Plugin/Filtering/Configuration/Reject.php @@ -29,8 +29,6 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->scalarNode('reason') - ->isRequired() - ->cannotBeEmpty() ->validate() ->ifTrue(isExpression()) ->then(asExpression()) diff --git a/src/Plugin/Filtering/DTO/Exclusion.php b/src/Plugin/Filtering/DTO/Exclusion.php new file mode 100644 index 00000000..7dfc1af5 --- /dev/null +++ b/src/Plugin/Filtering/DTO/Exclusion.php @@ -0,0 +1,15 @@ +withExclusions( - compileExpression($interpreter, $condition['when']) + new Filtering\DTO\Exclusion( + compileExpression($interpreter, $condition['when']), + compileValueWhenExpression($interpreter, $condition['reason']) ?: null, + ), ); } From 299ee8744636358c4c9e62b972f08d1fedf6db89 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 27 Oct 2023 15:32:33 +0200 Subject: [PATCH 06/10] rename new option serialize_rejection by rejection_serializer --- src/Plugin/Filtering/Builder/Reject.php | 8 ++++---- src/Plugin/Filtering/Configuration/Reject.php | 2 +- src/Plugin/Filtering/Factory/Reject.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index a84ded29..a59b9257 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -16,7 +16,7 @@ final class Reject implements StepBuilderInterface private ?Node\Expr $logger = null; private ?Node\Expr $rejection = null; private ?Node\Expr $state = null; - private ?Node\Expr $serialize_rejection = null; + private ?Node\Expr $rejection_serializer = null; /** @var list */ private array $exclusions = []; @@ -43,9 +43,9 @@ public function withState(Node\Expr $state): self return $this; } - public function withSerialiazeRejection(Node\Expr $serialize_rejection): self + public function withRejectionSerializer(Node\Expr $rejection_serializer): self { - $this->serialize_rejection = $serialize_rejection; + $this->rejection_serializer = $rejection_serializer; return $this; } @@ -133,7 +133,7 @@ class: new Node\Stmt\Class_(null, [ new Node\Expr\New_( new Node\Name\FullyQualified(RejectionResultBucket::class), [ - null !== $this->serialize_rejection ? new Node\Arg($this->serialize_rejection) : new Node\Arg(new Node\Expr\Variable('input')), + null !== $this->rejection_serializer ? new Node\Arg($this->rejection_serializer) : new Node\Arg(new Node\Expr\Variable('input')), ] ), ), diff --git a/src/Plugin/Filtering/Configuration/Reject.php b/src/Plugin/Filtering/Configuration/Reject.php index ace4c919..d08f422a 100644 --- a/src/Plugin/Filtering/Configuration/Reject.php +++ b/src/Plugin/Filtering/Configuration/Reject.php @@ -28,7 +28,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->then(asExpression()) ->end() ->end() - ->scalarNode('serialize_rejection') + ->scalarNode('rejection_serializer') ->cannotBeEmpty() ->validate() ->ifTrue(isExpression()) diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index d809c5b5..8641636a 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -71,8 +71,8 @@ public function compile(array $config): Repository\Reject $builder->withExclusions( compileExpression($interpreter, $condition['when']) ); - if (\array_key_exists('serialize_rejection', $condition)) { - $builder->withSerialiazeRejection(compileExpression($interpreter, $condition['serialize_rejection'])); + if (\array_key_exists('rejection_serializer', $condition)) { + $builder->withRejectionSerializer(compileExpression($interpreter, $condition['rejection_serializer'])); } } From b06361ec2f89099913344e09018ddd9c59ccfc85 Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 30 Oct 2023 14:58:07 +0100 Subject: [PATCH 07/10] Created a new builder to manage exclusions --- .../Filtering/Builder/ExclusionsBuilder.php | 61 +++++++++++++++++++ src/Plugin/Filtering/Builder/Reject.php | 45 ++------------ src/Plugin/Filtering/DTO/Exclusion.php | 15 ----- src/Plugin/Filtering/Factory/Reject.php | 9 +-- 4 files changed, 70 insertions(+), 60 deletions(-) create mode 100644 src/Plugin/Filtering/Builder/ExclusionsBuilder.php delete mode 100644 src/Plugin/Filtering/DTO/Exclusion.php diff --git a/src/Plugin/Filtering/Builder/ExclusionsBuilder.php b/src/Plugin/Filtering/Builder/ExclusionsBuilder.php new file mode 100644 index 00000000..694de9d9 --- /dev/null +++ b/src/Plugin/Filtering/Builder/ExclusionsBuilder.php @@ -0,0 +1,61 @@ +> */ + private array $exclusions = []; + + public function withCondition(Node\Expr $condition, ?Node\Expr $reason = null):self + { + $this->exclusions[] = [ + 'condition' => $condition, + 'reason' => $reason, + ]; + + return $this; + } + + public function getNode(): array + { + $statements = []; + foreach ($this->exclusions as $exclusion) { + $statements[] = new Node\Stmt\If_( + $exclusion['condition'], + [ + 'stmts' => [ + new Node\Stmt\Expression( + new Node\Expr\Assign( + new Node\Expr\Variable('input'), + new Node\Expr\Yield_( + new Node\Expr\New_( + \array_key_exists('reason', $exclusion) ? new Node\Name\FullyQualified(RejectionWithReasonResultBucket::class) : new Node\Name\FullyQualified(RejectionResultBucket::class), + [ + new Node\Arg(new Node\Expr\Variable('input')), + \array_key_exists('reason', $exclusion) ? new Node\Arg($exclusion['reason']) : new Node\Arg( + new Node\Expr\ConstFetch( + new Node\Name(null) + ), + ), + ] + ), + ), + ), + ), + new Node\Stmt\Continue_(), + ], + ] + ); + } + + return $statements; + } +} diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index 912d030a..f4bbfe51 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -7,7 +7,6 @@ use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Component\Bucket\RejectionWithReasonResultBucket; -use Kiboko\Component\Satellite\Plugin\Filtering\DTO\Exclusion; use Kiboko\Contract\Configurator\StepBuilderInterface; use Kiboko\Contract\Pipeline\TransformerInterface; use PhpParser\Builder; @@ -18,8 +17,7 @@ final class Reject implements StepBuilderInterface private ?Node\Expr $logger = null; private ?Node\Expr $rejection = null; private ?Node\Expr $state = null; - /** @var list */ - private array $exclusions = []; + private ?ExclusionsBuilder $exclusions = null; public function withLogger(Node\Expr $logger): self { @@ -42,48 +40,13 @@ public function withState(Node\Expr $state): self return $this; } - public function withExclusions(Exclusion ...$exclusions): self + public function withExclusions(ExclusionsBuilder $builder): self { - array_push($this->exclusions, ...$exclusions); + $this->exclusions = $builder; return $this; } - private function buildExclusions(Exclusion ...$exclusions): array - { - $statements = []; - foreach ($exclusions as $exclusion) { - $statements[] = new Node\Stmt\If_( - $exclusion->when, - [ - 'stmts' => [ - new Node\Stmt\Expression( - new Node\Expr\Assign( - new Node\Expr\Variable('input'), - new Node\Expr\Yield_( - new Node\Expr\New_( - $exclusion->reason ? new Node\Name\FullyQualified(RejectionWithReasonResultBucket::class) : new Node\Name\FullyQualified(RejectionResultBucket::class), - [ - new Node\Arg(new Node\Expr\Variable('input')), - $exclusion->reason ? new Node\Arg($exclusion->reason) : new Node\Arg( - new Node\Expr\ConstFetch( - new Node\Name(null) - ), - ), - ] - ), - ), - ), - ), - new Node\Stmt\Continue_(), - ], - ] - ); - } - - return $statements; - } - public function getNode(): Node { return new Node\Expr\New_( @@ -107,7 +70,7 @@ class: new Node\Stmt\Class_(null, [ new Node\Name('true'), ), [ - ...$this->buildExclusions(...$this->exclusions), + ...$this->exclusions->getNode(), new Node\Stmt\Expression( new Node\Expr\Assign( new Node\Expr\Variable('input'), diff --git a/src/Plugin/Filtering/DTO/Exclusion.php b/src/Plugin/Filtering/DTO/Exclusion.php deleted file mode 100644 index 7dfc1af5..00000000 --- a/src/Plugin/Filtering/DTO/Exclusion.php +++ /dev/null @@ -1,15 +0,0 @@ -withExclusions( - new Filtering\DTO\Exclusion( + $exclusionBuilder + ->withCondition( compileExpression($interpreter, $condition['when']), compileValueWhenExpression($interpreter, $condition['reason']) ?: null, - ), - ); + ); } + $builder->withExclusions($exclusionBuilder); return $repository; } From 1f751d132185cb0b00d8cbaac5c0fb16af8ed5c6 Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 31 Oct 2023 09:19:11 +0100 Subject: [PATCH 08/10] Fixed condition to avoid a fatal error --- src/Plugin/Filtering/Builder/ExclusionsBuilder.php | 6 +++--- src/Plugin/Filtering/Factory/Reject.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Filtering/Builder/ExclusionsBuilder.php b/src/Plugin/Filtering/Builder/ExclusionsBuilder.php index 694de9d9..e7cf1c3b 100644 --- a/src/Plugin/Filtering/Builder/ExclusionsBuilder.php +++ b/src/Plugin/Filtering/Builder/ExclusionsBuilder.php @@ -9,7 +9,7 @@ use PhpParser\Builder; use PhpParser\Node; -final class ExclusionsBuilder extends Builder +final class ExclusionsBuilder implements Builder { /** @var list> */ private array $exclusions = []; @@ -24,7 +24,7 @@ public function withCondition(Node\Expr $condition, ?Node\Expr $reason = null):s return $this; } - public function getNode(): array + public function getNode(): Node { $statements = []; foreach ($this->exclusions as $exclusion) { @@ -56,6 +56,6 @@ public function getNode(): array ); } - return $statements; + return new Node; } } diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index d2028684..5d3772e2 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -73,7 +73,7 @@ public function compile(array $config): Repository\Reject $exclusionBuilder ->withCondition( compileExpression($interpreter, $condition['when']), - compileValueWhenExpression($interpreter, $condition['reason']) ?: null, + \array_key_exists('reason', $condition) ? compileValueWhenExpression($interpreter, $condition['reason']) : null, ); } $builder->withExclusions($exclusionBuilder); From 69b57456bb5ea628f61cd1db45418540cb0000c8 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 17 Nov 2023 09:57:19 +0000 Subject: [PATCH 09/10] [rector] Rector fixes --- src/Plugin/Filtering/Factory/Reject.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index 80c8d5a4..5d3772e2 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -74,7 +74,6 @@ public function compile(array $config): Repository\Reject ->withCondition( compileExpression($interpreter, $condition['when']), \array_key_exists('reason', $condition) ? compileValueWhenExpression($interpreter, $condition['reason']) : null, - \array_key_exists('rejection_serializer', $condition) ? compileValueWhenExpression($interpreter, $condition['rejection_serializer']) : null, ); } $builder->withExclusions($exclusionBuilder); From 931b59e2b6452ef8a2f0839734aad63558a641af Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 17 Nov 2023 11:00:20 +0100 Subject: [PATCH 10/10] php cs-fixer --- src/Plugin/Filtering/Builder/ExclusionsBuilder.php | 7 ++++--- src/Plugin/Filtering/Builder/Reject.php | 2 -- src/Plugin/Filtering/Factory/Reject.php | 7 ++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Plugin/Filtering/Builder/ExclusionsBuilder.php b/src/Plugin/Filtering/Builder/ExclusionsBuilder.php index e7cf1c3b..8be69a58 100644 --- a/src/Plugin/Filtering/Builder/ExclusionsBuilder.php +++ b/src/Plugin/Filtering/Builder/ExclusionsBuilder.php @@ -14,11 +14,12 @@ final class ExclusionsBuilder implements Builder /** @var list> */ private array $exclusions = []; - public function withCondition(Node\Expr $condition, ?Node\Expr $reason = null):self + public function withCondition(Node\Expr $condition, Node\Expr $reason = null, Node\Expr $serializeRejection = null): self { $this->exclusions[] = [ 'condition' => $condition, 'reason' => $reason, + 'rejection_serializer' => $serializeRejection, ]; return $this; @@ -39,7 +40,7 @@ public function getNode(): Node new Node\Expr\New_( \array_key_exists('reason', $exclusion) ? new Node\Name\FullyQualified(RejectionWithReasonResultBucket::class) : new Node\Name\FullyQualified(RejectionResultBucket::class), [ - new Node\Arg(new Node\Expr\Variable('input')), + null !== $this->{$exclusion}['rejection_serializer'] ? new Node\Arg($this->{$exclusion}['rejection_serializer']) : new Node\Arg(new Node\Expr\Variable('input')), \array_key_exists('reason', $exclusion) ? new Node\Arg($exclusion['reason']) : new Node\Arg( new Node\Expr\ConstFetch( new Node\Name(null) @@ -56,6 +57,6 @@ public function getNode(): Node ); } - return new Node; + return new Node(); } } diff --git a/src/Plugin/Filtering/Builder/Reject.php b/src/Plugin/Filtering/Builder/Reject.php index 15e41881..675e68c1 100644 --- a/src/Plugin/Filtering/Builder/Reject.php +++ b/src/Plugin/Filtering/Builder/Reject.php @@ -5,8 +5,6 @@ namespace Kiboko\Component\Satellite\Plugin\Filtering\Builder; use Kiboko\Component\Bucket\AcceptanceResultBucket; -use Kiboko\Component\Bucket\RejectionResultBucket; -use Kiboko\Component\Bucket\RejectionWithReasonResultBucket; use Kiboko\Contract\Configurator\StepBuilderInterface; use Kiboko\Contract\Pipeline\TransformerInterface; use PhpParser\Builder; diff --git a/src/Plugin/Filtering/Factory/Reject.php b/src/Plugin/Filtering/Factory/Reject.php index 80c8d5a4..a9100aa3 100644 --- a/src/Plugin/Filtering/Factory/Reject.php +++ b/src/Plugin/Filtering/Factory/Reject.php @@ -41,7 +41,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -52,7 +52,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -75,7 +75,8 @@ public function compile(array $config): Repository\Reject compileExpression($interpreter, $condition['when']), \array_key_exists('reason', $condition) ? compileValueWhenExpression($interpreter, $condition['reason']) : null, \array_key_exists('rejection_serializer', $condition) ? compileValueWhenExpression($interpreter, $condition['rejection_serializer']) : null, - ); + ) + ; } $builder->withExclusions($exclusionBuilder);