From 24439ad9753a04f1ac60260a0482c036d5671355 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 May 2024 16:12:50 +0200 Subject: [PATCH 1/8] Add new parameter for endpoint category, with_enriched_attributes to pull template's attributes on enriched categories --- src/Builder/Capacity/Extractor/All.php | 15 +++++++++++++++ src/Capacity/Extractor/All.php | 4 ++++ src/Configuration/Extractor.php | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/src/Builder/Capacity/Extractor/All.php b/src/Builder/Capacity/Extractor/All.php index 1fa6c0a..c8dfee6 100644 --- a/src/Builder/Capacity/Extractor/All.php +++ b/src/Builder/Capacity/Extractor/All.php @@ -15,6 +15,7 @@ final class All implements Builder private null|Node\Expr $code = null; private null|Node\Expr $referenceEntity = null; private null|Node\Expr $referenceEntityAttributeCode = null; + private null|Node\Expr $withEnrichedAttributes = null; public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { @@ -51,6 +52,13 @@ public function withReferenceEntityAttributeOption(?Node\Expr $referenceEntityAt return $this; } + public function withEnrichedAttributes(?Node\Expr $withEnrichedAttributes): self + { + $this->withEnrichedAttributes = $withEnrichedAttributes; + + return $this; + } + public function getNode(): Node { if (null === $this->endpoint) { @@ -141,6 +149,13 @@ private function compileArguments(): array ); } + if (null !== $this->withEnrichedAttributes) { + $args[] = new Node\Arg( + value: $this->withEnrichedAttributes, + name: new Node\Identifier('withEnrichedAttributes'), + ); + } + return $args; } } diff --git a/src/Capacity/Extractor/All.php b/src/Capacity/Extractor/All.php index 47cdf98..de0f8da 100644 --- a/src/Capacity/Extractor/All.php +++ b/src/Capacity/Extractor/All.php @@ -98,6 +98,10 @@ public function getBuilder(array $config): Builder $builder->withSearch($this->compileFilters(...$config['search'])); } + if (isset($config['with_enriched_attributes']) && $config['type'] === 'category') { + $builder->withEnrichedAttributes(compileValueWhenExpression($this->interpreter, $config['with_enriched_attributes'])); + } + if (\in_array($config['type'], ['attributeOption', 'assetManager']) && \array_key_exists('code', $config)) { $builder->withCode(compileValueWhenExpression($this->interpreter, $config['code'])); } diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index 484d3da..c19f817 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -238,6 +238,12 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder ->then(asExpression()) ->end() ->end() + ->scalarNode('with_enriched_attributes') + ->validate() + ->ifTrue(isExpression()) + ->then(asExpression()) + ->end() + ->end() ->append((new Search())->getConfigTreeBuilder()->getRootNode()) ->end() ; From 772bfb6c997b27de0b7b90df270d38f0735e8c54 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 May 2024 16:34:55 +0200 Subject: [PATCH 2/8] code format commit --- src/Builder/AlternativeLookup.php | 3 ++- src/Builder/Capacity/Extractor/All.php | 12 ++++++------ src/Builder/Capacity/Extractor/Get.php | 8 +++++--- src/Builder/Capacity/Extractor/ListPerPage.php | 10 ++++++---- src/Builder/Capacity/Loader/Upsert.php | 10 +++++----- src/Builder/Capacity/Loader/UpsertList.php | 8 ++++---- src/Builder/Capacity/Lookup/All.php | 10 ++++++---- src/Builder/Capacity/Lookup/Download.php | 8 +++++--- src/Builder/Capacity/Lookup/Get.php | 12 +++++++----- src/Builder/Capacity/Lookup/ListPerPage.php | 10 ++++++---- src/Builder/Client.php | 4 +++- src/Builder/ConditionalLookup.php | 4 +++- src/Builder/Extractor.php | 3 ++- src/Builder/Inline.php | 4 +++- src/Builder/Loader.php | 3 ++- src/Builder/Lookup.php | 4 +++- src/Builder/Search.php | 9 +++++---- src/Capacity/Extractor/All.php | 6 ++++-- src/Capacity/Extractor/Get.php | 4 +++- src/Capacity/Extractor/ListPerPage.php | 4 +++- src/Capacity/Loader/Upsert.php | 4 +++- src/Capacity/Lookup/All.php | 4 +++- src/Capacity/Lookup/Download.php | 4 +++- src/Capacity/Lookup/Get.php | 4 +++- src/Capacity/Lookup/ListPerPage.php | 4 +++- src/Configuration/Loader.php | 2 +- src/Factory/NoApplicableCapacityException.php | 4 +++- src/MissingAuthenticationMethodException.php | 4 +++- src/MissingEndpointException.php | 4 +++- src/MissingParameterException.php | 4 +++- src/Service.php | 2 +- 31 files changed, 112 insertions(+), 64 deletions(-) diff --git a/src/Builder/AlternativeLookup.php b/src/Builder/AlternativeLookup.php index 7c5e33b..c3cee87 100644 --- a/src/Builder/AlternativeLookup.php +++ b/src/Builder/AlternativeLookup.php @@ -14,7 +14,8 @@ final class AlternativeLookup implements Builder public function __construct( private readonly Builder $capacity, - ) {} + ) { + } public function withMerge(Builder $merge): self { diff --git a/src/Builder/Capacity/Extractor/All.php b/src/Builder/Capacity/Extractor/All.php index c8dfee6..dbff9c9 100644 --- a/src/Builder/Capacity/Extractor/All.php +++ b/src/Builder/Capacity/Extractor/All.php @@ -10,12 +10,12 @@ final class All implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $search = null; - private null|Node\Expr $code = null; - private null|Node\Expr $referenceEntity = null; - private null|Node\Expr $referenceEntityAttributeCode = null; - private null|Node\Expr $withEnrichedAttributes = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $search = null; + private ?Node\Expr $code = null; + private ?Node\Expr $referenceEntity = null; + private ?Node\Expr $referenceEntityAttributeCode = null; + private ?Node\Expr $withEnrichedAttributes = null; public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Extractor/Get.php b/src/Builder/Capacity/Extractor/Get.php index 8816611..bf5a2a4 100644 --- a/src/Builder/Capacity/Extractor/Get.php +++ b/src/Builder/Capacity/Extractor/Get.php @@ -10,10 +10,12 @@ final class Get implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $identifier = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $identifier = null; - public function __construct() {} + public function __construct() + { + } public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Extractor/ListPerPage.php b/src/Builder/Capacity/Extractor/ListPerPage.php index ea019f2..23287b8 100644 --- a/src/Builder/Capacity/Extractor/ListPerPage.php +++ b/src/Builder/Capacity/Extractor/ListPerPage.php @@ -10,11 +10,13 @@ final class ListPerPage implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $search = null; - private null|Node\Expr $code = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $search = null; + private ?Node\Expr $code = null; - public function __construct() {} + public function __construct() + { + } public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Loader/Upsert.php b/src/Builder/Capacity/Loader/Upsert.php index 52501f8..77ef1d1 100644 --- a/src/Builder/Capacity/Loader/Upsert.php +++ b/src/Builder/Capacity/Loader/Upsert.php @@ -11,11 +11,11 @@ final class Upsert implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $code = null; - private null|Node\Expr $data = null; - private null|Node\Expr $referenceEntity = null; - private null|Node\Expr $referenceEntityAttribute = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $code = null; + private ?Node\Expr $data = null; + private ?Node\Expr $referenceEntity = null; + private ?Node\Expr $referenceEntityAttribute = null; public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Loader/UpsertList.php b/src/Builder/Capacity/Loader/UpsertList.php index 38db6bd..9b67da4 100644 --- a/src/Builder/Capacity/Loader/UpsertList.php +++ b/src/Builder/Capacity/Loader/UpsertList.php @@ -11,10 +11,10 @@ final class UpsertList implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $data = null; - private null|Node\Expr $referenceEntity = null; - private null|Node\Expr $attributeCode = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $data = null; + private ?Node\Expr $referenceEntity = null; + private ?Node\Expr $attributeCode = null; public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Lookup/All.php b/src/Builder/Capacity/Lookup/All.php index f4d1718..e51c6ec 100644 --- a/src/Builder/Capacity/Lookup/All.php +++ b/src/Builder/Capacity/Lookup/All.php @@ -10,12 +10,14 @@ final class All implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $search = null; - private null|Node\Expr $code = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $search = null; + private ?Node\Expr $code = null; private string $type = ''; - public function __construct() {} + public function __construct() + { + } public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Lookup/Download.php b/src/Builder/Capacity/Lookup/Download.php index 4e0673a..cf70684 100644 --- a/src/Builder/Capacity/Lookup/Download.php +++ b/src/Builder/Capacity/Lookup/Download.php @@ -11,10 +11,12 @@ final class Download implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $file = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $file = null; - public function __construct() {} + public function __construct() + { + } public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Lookup/Get.php b/src/Builder/Capacity/Lookup/Get.php index 33f1dcf..b248691 100644 --- a/src/Builder/Capacity/Lookup/Get.php +++ b/src/Builder/Capacity/Lookup/Get.php @@ -10,12 +10,14 @@ final class Get implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $identifier = null; - private null|Node\Expr $code = null; - private null|string $type = ''; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $identifier = null; + private ?Node\Expr $code = null; + private ?string $type = ''; - public function __construct() {} + public function __construct() + { + } public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Capacity/Lookup/ListPerPage.php b/src/Builder/Capacity/Lookup/ListPerPage.php index 2b5fce0..a7a7ca0 100644 --- a/src/Builder/Capacity/Lookup/ListPerPage.php +++ b/src/Builder/Capacity/Lookup/ListPerPage.php @@ -10,11 +10,13 @@ final class ListPerPage implements Builder { - private null|Node\Expr|Node\Identifier $endpoint = null; - private null|Node\Expr $search = null; - private null|Node\Expr $code = null; + private Node\Expr|Node\Identifier|null $endpoint = null; + private ?Node\Expr $search = null; + private ?Node\Expr $code = null; - public function __construct() {} + public function __construct() + { + } public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { diff --git a/src/Builder/Client.php b/src/Builder/Client.php index 3293aa5..a143a3f 100644 --- a/src/Builder/Client.php +++ b/src/Builder/Client.php @@ -19,7 +19,9 @@ final class Client implements Builder private ?Node\Expr $httpStreamFactory = null; private ?Node\Expr $fileSystem = null; - public function __construct(private readonly Node\Expr $baseUrl, private readonly Node\Expr $clientId, private readonly Node\Expr $secret) {} + public function __construct(private readonly Node\Expr $baseUrl, private readonly Node\Expr $clientId, private readonly Node\Expr $secret) + { + } public function withToken(Node\Expr $token, Node\Expr $refreshToken): self { diff --git a/src/Builder/ConditionalLookup.php b/src/Builder/ConditionalLookup.php index 2ca716b..3b6bc65 100644 --- a/src/Builder/ConditionalLookup.php +++ b/src/Builder/ConditionalLookup.php @@ -14,7 +14,9 @@ final class ConditionalLookup implements StepBuilderInterface private iterable $alternatives = []; private ?Node\Expr $client = null; - public function __construct() {} + public function __construct() + { + } public function withClient(Node\Expr $client): self { diff --git a/src/Builder/Extractor.php b/src/Builder/Extractor.php index ed74d05..8651637 100644 --- a/src/Builder/Extractor.php +++ b/src/Builder/Extractor.php @@ -15,7 +15,8 @@ final class Extractor implements StepBuilderInterface public function __construct( private readonly Builder $capacity, - ) {} + ) { + } public function withClient(Node\Expr $client): self { diff --git a/src/Builder/Inline.php b/src/Builder/Inline.php index 4cb0d5d..abcafcd 100644 --- a/src/Builder/Inline.php +++ b/src/Builder/Inline.php @@ -13,7 +13,9 @@ final readonly class Inline implements Builder { - public function __construct(private ArrayBuilderInterface|ObjectBuilderInterface $mapper) {} + public function __construct(private ArrayBuilderInterface|ObjectBuilderInterface $mapper) + { + } public function getNode(): Node { diff --git a/src/Builder/Loader.php b/src/Builder/Loader.php index 99e9b4f..d5d4eb8 100644 --- a/src/Builder/Loader.php +++ b/src/Builder/Loader.php @@ -15,7 +15,8 @@ final class Loader implements StepBuilderInterface public function __construct( private readonly Builder $capacity, - ) {} + ) { + } public function withClient(Node\Expr $client): self { diff --git a/src/Builder/Lookup.php b/src/Builder/Lookup.php index 77800da..bd3a004 100644 --- a/src/Builder/Lookup.php +++ b/src/Builder/Lookup.php @@ -12,7 +12,9 @@ final class Lookup implements StepBuilderInterface private ?Node\Expr $logger = null; private ?Node\Expr $client = null; - public function __construct(private readonly AlternativeLookup $alternative) {} + public function __construct(private readonly AlternativeLookup $alternative) + { + } public function withClient(Node\Expr $client): self { diff --git a/src/Builder/Search.php b/src/Builder/Search.php index 528f63b..14c92f4 100644 --- a/src/Builder/Search.php +++ b/src/Builder/Search.php @@ -11,14 +11,15 @@ final class Search implements Builder { public function __construct( private array $filters = [] - ) {} + ) { + } public function addFilter( Node\Expr $field, Node\Expr $operator, - Node\Expr $value = null, - Node\Expr $scope = null, - Node\Expr $locale = null + ?Node\Expr $value = null, + ?Node\Expr $scope = null, + ?Node\Expr $locale = null ): self { $arguments = [ new Node\Arg( diff --git a/src/Capacity/Extractor/All.php b/src/Capacity/Extractor/All.php index de0f8da..4e0a536 100644 --- a/src/Capacity/Extractor/All.php +++ b/src/Capacity/Extractor/All.php @@ -55,7 +55,9 @@ final class All implements Akeneo\Capacity\CapacityInterface 'UNCLASSIFIED', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { @@ -98,7 +100,7 @@ public function getBuilder(array $config): Builder $builder->withSearch($this->compileFilters(...$config['search'])); } - if (isset($config['with_enriched_attributes']) && $config['type'] === 'category') { + if (isset($config['with_enriched_attributes']) && 'category' === $config['type']) { $builder->withEnrichedAttributes(compileValueWhenExpression($this->interpreter, $config['with_enriched_attributes'])); } diff --git a/src/Capacity/Extractor/Get.php b/src/Capacity/Extractor/Get.php index a6a0b2d..f7f897e 100644 --- a/src/Capacity/Extractor/Get.php +++ b/src/Capacity/Extractor/Get.php @@ -43,7 +43,9 @@ final class Get implements Akeneo\Capacity\CapacityInterface 'assetManager', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Capacity/Extractor/ListPerPage.php b/src/Capacity/Extractor/ListPerPage.php index a743b1e..644d94b 100644 --- a/src/Capacity/Extractor/ListPerPage.php +++ b/src/Capacity/Extractor/ListPerPage.php @@ -53,7 +53,9 @@ final class ListPerPage implements Akeneo\Capacity\CapacityInterface 'UNCLASSIFIED', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Capacity/Loader/Upsert.php b/src/Capacity/Loader/Upsert.php index f5b983d..5f939b9 100644 --- a/src/Capacity/Loader/Upsert.php +++ b/src/Capacity/Loader/Upsert.php @@ -45,7 +45,9 @@ final class Upsert implements Akeneo\Capacity\CapacityInterface 'referenceEntity', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Capacity/Lookup/All.php b/src/Capacity/Lookup/All.php index bc6637b..2ac7f6f 100644 --- a/src/Capacity/Lookup/All.php +++ b/src/Capacity/Lookup/All.php @@ -54,7 +54,9 @@ final class All implements Akeneo\Capacity\CapacityInterface 'UNCLASSIFIED', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Capacity/Lookup/Download.php b/src/Capacity/Lookup/Download.php index 1a15cde..fa46a6c 100644 --- a/src/Capacity/Lookup/Download.php +++ b/src/Capacity/Lookup/Download.php @@ -22,7 +22,9 @@ final class Download implements Akeneo\Capacity\CapacityInterface 'assetMediaFile', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Capacity/Lookup/Get.php b/src/Capacity/Lookup/Get.php index 6be374d..5336e60 100644 --- a/src/Capacity/Lookup/Get.php +++ b/src/Capacity/Lookup/Get.php @@ -43,7 +43,9 @@ final class Get implements Akeneo\Capacity\CapacityInterface 'assetManager', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Capacity/Lookup/ListPerPage.php b/src/Capacity/Lookup/ListPerPage.php index 5ee4f69..4f02b46 100644 --- a/src/Capacity/Lookup/ListPerPage.php +++ b/src/Capacity/Lookup/ListPerPage.php @@ -53,7 +53,9 @@ final class ListPerPage implements Akeneo\Capacity\CapacityInterface 'UNCLASSIFIED', ]; - public function __construct(private readonly ExpressionLanguage $interpreter) {} + public function __construct(private readonly ExpressionLanguage $interpreter) + { + } public function applies(array $config): bool { diff --git a/src/Configuration/Loader.php b/src/Configuration/Loader.php index 1efcc9c..3fefd8c 100644 --- a/src/Configuration/Loader.php +++ b/src/Configuration/Loader.php @@ -175,7 +175,7 @@ final class Loader implements PluginConfigurationInterface ], ]; - public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder + public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder { $builder = new Config\Definition\Builder\TreeBuilder('loader'); diff --git a/src/Factory/NoApplicableCapacityException.php b/src/Factory/NoApplicableCapacityException.php index 38ef19c..779c4c4 100644 --- a/src/Factory/NoApplicableCapacityException.php +++ b/src/Factory/NoApplicableCapacityException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Akeneo\Factory; -final class NoApplicableCapacityException extends \OutOfRangeException {} +final class NoApplicableCapacityException extends \OutOfRangeException +{ +} diff --git a/src/MissingAuthenticationMethodException.php b/src/MissingAuthenticationMethodException.php index c666271..58d3fd6 100644 --- a/src/MissingAuthenticationMethodException.php +++ b/src/MissingAuthenticationMethodException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Akeneo; -final class MissingAuthenticationMethodException extends \RuntimeException {} +final class MissingAuthenticationMethodException extends \RuntimeException +{ +} diff --git a/src/MissingEndpointException.php b/src/MissingEndpointException.php index 04cc6c2..37d752f 100644 --- a/src/MissingEndpointException.php +++ b/src/MissingEndpointException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Akeneo; -final class MissingEndpointException extends \RuntimeException {} +final class MissingEndpointException extends \RuntimeException +{ +} diff --git a/src/MissingParameterException.php b/src/MissingParameterException.php index b7f1de9..7375c9f 100644 --- a/src/MissingParameterException.php +++ b/src/MissingParameterException.php @@ -4,4 +4,6 @@ namespace Kiboko\Plugin\Akeneo; -final class MissingParameterException extends \UnexpectedValueException {} +final class MissingParameterException extends \UnexpectedValueException +{ +} diff --git a/src/Service.php b/src/Service.php index 0f08aa3..325e503 100644 --- a/src/Service.php +++ b/src/Service.php @@ -50,7 +50,7 @@ public function normalize(array $config): array try { return $this->processor->processConfiguration($this->configuration, $config); } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { - throw new COnfigurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); + throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } From 3a269abd10a434072a61542a87ca0fdd02115c2f Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 May 2024 16:55:47 +0200 Subject: [PATCH 3/8] Add the new parameter to the queryParameters element, manage the existence of the search parameter --- src/Builder/Capacity/Extractor/All.php | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Builder/Capacity/Extractor/All.php b/src/Builder/Capacity/Extractor/All.php index dbff9c9..49727a6 100644 --- a/src/Builder/Capacity/Extractor/All.php +++ b/src/Builder/Capacity/Extractor/All.php @@ -117,9 +117,21 @@ private function compileArguments(): array $args = []; if (null !== $this->search) { + $items = $this->compileSearch(); + if (null !== $this->withEnrichedAttributes) { + $items = array_merge( + $this->compileSearch(), + [ + new Node\Expr\ArrayItem( + $this->withEnrichedAttributes, + new Node\Scalar\String_('with_enriched_attributes'), + ) + ] + ); + } $args[] = new Node\Arg( value: new Node\Expr\Array_( - items: $this->compileSearch(), + items: $items, attributes: [ 'kind' => Node\Expr\Array_::KIND_SHORT, ] @@ -149,10 +161,20 @@ private function compileArguments(): array ); } - if (null !== $this->withEnrichedAttributes) { + if (null !== $this->withEnrichedAttributes && null === $this->search) { $args[] = new Node\Arg( - value: $this->withEnrichedAttributes, - name: new Node\Identifier('withEnrichedAttributes'), + value: new Node\Expr\Array_( + items: [ + new Node\Expr\ArrayItem( + $this->withEnrichedAttributes, + new Node\Scalar\String_('with_enriched_attributes'), + ), + ], + attributes: [ + 'kind' => Node\Expr\Array_::KIND_SHORT, + ] + ), + name: new Node\Identifier('queryParameters'), ); } From e14c1d105990d15d16197191e2dd9564278e8f89 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 May 2024 17:19:19 +0200 Subject: [PATCH 4/8] code format commit --- src/Builder/Capacity/Extractor/All.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Builder/Capacity/Extractor/All.php b/src/Builder/Capacity/Extractor/All.php index 49727a6..3e39a74 100644 --- a/src/Builder/Capacity/Extractor/All.php +++ b/src/Builder/Capacity/Extractor/All.php @@ -125,7 +125,7 @@ private function compileArguments(): array new Node\Expr\ArrayItem( $this->withEnrichedAttributes, new Node\Scalar\String_('with_enriched_attributes'), - ) + ), ] ); } @@ -165,7 +165,7 @@ private function compileArguments(): array $args[] = new Node\Arg( value: new Node\Expr\Array_( items: [ - new Node\Expr\ArrayItem( + new Node\Expr\ArrayItem( $this->withEnrichedAttributes, new Node\Scalar\String_('with_enriched_attributes'), ), From 320bdd50f552e7f6616c71bc5265e84565f62a99 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 27 May 2024 09:50:32 +0200 Subject: [PATCH 5/8] remove useless empty constructorn change new param node from scalar to boolean --- src/Builder/Capacity/Extractor/Get.php | 4 ---- src/Builder/Capacity/Extractor/ListPerPage.php | 4 ---- src/Builder/Capacity/Lookup/Get.php | 4 ---- src/Builder/Capacity/Lookup/ListPerPage.php | 4 ---- src/Configuration/Extractor.php | 3 ++- 5 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Builder/Capacity/Extractor/Get.php b/src/Builder/Capacity/Extractor/Get.php index bf5a2a4..21f12b2 100644 --- a/src/Builder/Capacity/Extractor/Get.php +++ b/src/Builder/Capacity/Extractor/Get.php @@ -13,10 +13,6 @@ final class Get implements Builder private Node\Expr|Node\Identifier|null $endpoint = null; private ?Node\Expr $identifier = null; - public function __construct() - { - } - public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { $this->endpoint = $endpoint; diff --git a/src/Builder/Capacity/Extractor/ListPerPage.php b/src/Builder/Capacity/Extractor/ListPerPage.php index 23287b8..c5fac1e 100644 --- a/src/Builder/Capacity/Extractor/ListPerPage.php +++ b/src/Builder/Capacity/Extractor/ListPerPage.php @@ -14,10 +14,6 @@ final class ListPerPage implements Builder private ?Node\Expr $search = null; private ?Node\Expr $code = null; - public function __construct() - { - } - public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { $this->endpoint = $endpoint; diff --git a/src/Builder/Capacity/Lookup/Get.php b/src/Builder/Capacity/Lookup/Get.php index b248691..41f6b34 100644 --- a/src/Builder/Capacity/Lookup/Get.php +++ b/src/Builder/Capacity/Lookup/Get.php @@ -15,10 +15,6 @@ final class Get implements Builder private ?Node\Expr $code = null; private ?string $type = ''; - public function __construct() - { - } - public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { $this->endpoint = $endpoint; diff --git a/src/Builder/Capacity/Lookup/ListPerPage.php b/src/Builder/Capacity/Lookup/ListPerPage.php index a7a7ca0..2527389 100644 --- a/src/Builder/Capacity/Lookup/ListPerPage.php +++ b/src/Builder/Capacity/Lookup/ListPerPage.php @@ -14,10 +14,6 @@ final class ListPerPage implements Builder private ?Node\Expr $search = null; private ?Node\Expr $code = null; - public function __construct() - { - } - public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { $this->endpoint = $endpoint; diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index c19f817..c2e1fbb 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -238,7 +238,8 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder ->then(asExpression()) ->end() ->end() - ->scalarNode('with_enriched_attributes') + ->booleanNode('with_enriched_attributes') + ->defaultFalse() ->validate() ->ifTrue(isExpression()) ->then(asExpression()) From 3119b33c285809d28b20568d65a42e2964663d18 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 27 May 2024 10:39:02 +0200 Subject: [PATCH 6/8] remove default value on boolean node, add new dataset on ExtractorTest --- src/Builder/Capacity/Lookup/All.php | 4 ---- src/Configuration/Extractor.php | 9 ++++++++- tests/functional/Configuration/ExtractorTest.php | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Builder/Capacity/Lookup/All.php b/src/Builder/Capacity/Lookup/All.php index e51c6ec..336be1e 100644 --- a/src/Builder/Capacity/Lookup/All.php +++ b/src/Builder/Capacity/Lookup/All.php @@ -15,10 +15,6 @@ final class All implements Builder private ?Node\Expr $code = null; private string $type = ''; - public function __construct() - { - } - public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { $this->endpoint = $endpoint; diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index c2e1fbb..e661733 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -197,6 +197,14 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder && \in_array($data['type'], ['referenceEntityAttributeOption'], true)) ->thenInvalid('The reference_entity option should be used with the "referenceEntityAttributeOption" endpoint.') ->end() + ->validate() + ->ifTrue(fn ($data) => \array_key_exists('with_enriched_attributes', $data) && \array_key_exists('type', $data) && \in_array($data['type'], ['category'], true)) + ->thenInvalid('The with_enriched_attributes option should only be used with the "category" endpoint.') + ->end() +// ->validate() +// ->ifTrue(fn ($data) => \array_key_exists('with_enriched_attributes', $data) && \array_key_exists('method', $data) && 'all' !== $data['method']) +// ->thenInvalid('The with_enriched_attributes option should only be used with the "all" method.') +// ->end() ->children() ->scalarNode('type') ->isRequired() @@ -239,7 +247,6 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder ->end() ->end() ->booleanNode('with_enriched_attributes') - ->defaultFalse() ->validate() ->ifTrue(isExpression()) ->then(asExpression()) diff --git a/tests/functional/Configuration/ExtractorTest.php b/tests/functional/Configuration/ExtractorTest.php index 1e89067..bad5ed3 100644 --- a/tests/functional/Configuration/ExtractorTest.php +++ b/tests/functional/Configuration/ExtractorTest.php @@ -82,6 +82,20 @@ public static function validDataProvider(): iterable 'search' => [], ], ]; + yield [ + 'config' => [ + 'method' => 'all', + 'type' => 'category', + 'search' => [], + 'with_enriched_attributes' => true, + ], + 'expected' => [ + 'method' => 'all', + 'type' => 'category', + 'search' => [], + 'with_enriched_attributes' => true, + ], + ]; } #[\PHPUnit\Framework\Attributes\DataProvider('validDataProvider')] From aaf8ad0406d498fb18f9524599b1d4b1149025ff Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 27 May 2024 14:30:21 +0200 Subject: [PATCH 7/8] fix a condition, check the method type message --- src/Configuration/Extractor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index e661733..cd59a18 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -198,13 +198,13 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder ->thenInvalid('The reference_entity option should be used with the "referenceEntityAttributeOption" endpoint.') ->end() ->validate() - ->ifTrue(fn ($data) => \array_key_exists('with_enriched_attributes', $data) && \array_key_exists('type', $data) && \in_array($data['type'], ['category'], true)) + ->ifTrue(fn ($data) => \array_key_exists('with_enriched_attributes', $data) && \array_key_exists('type', $data) && !\in_array($data['type'], ['category'], true)) ->thenInvalid('The with_enriched_attributes option should only be used with the "category" endpoint.') ->end() -// ->validate() -// ->ifTrue(fn ($data) => \array_key_exists('with_enriched_attributes', $data) && \array_key_exists('method', $data) && 'all' !== $data['method']) -// ->thenInvalid('The with_enriched_attributes option should only be used with the "all" method.') -// ->end() + ->validate() + ->ifTrue(fn ($data) => \array_key_exists('with_enriched_attributes', $data) && \array_key_exists('method', $data) && 'all' !== $data['method']) + ->thenInvalid('The with_enriched_attributes option should only be used with the "all" method.') + ->end() ->children() ->scalarNode('type') ->isRequired() From a2925da207f87b26101d795c03021790e6413530 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 27 May 2024 14:44:15 +0200 Subject: [PATCH 8/8] remove useless constructors --- src/Builder/Capacity/Lookup/Download.php | 4 ---- src/Builder/ConditionalLookup.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/Builder/Capacity/Lookup/Download.php b/src/Builder/Capacity/Lookup/Download.php index cf70684..9953e28 100644 --- a/src/Builder/Capacity/Lookup/Download.php +++ b/src/Builder/Capacity/Lookup/Download.php @@ -14,10 +14,6 @@ final class Download implements Builder private Node\Expr|Node\Identifier|null $endpoint = null; private ?Node\Expr $file = null; - public function __construct() - { - } - public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self { $this->endpoint = $endpoint; diff --git a/src/Builder/ConditionalLookup.php b/src/Builder/ConditionalLookup.php index 3b6bc65..0a9cef5 100644 --- a/src/Builder/ConditionalLookup.php +++ b/src/Builder/ConditionalLookup.php @@ -14,10 +14,6 @@ final class ConditionalLookup implements StepBuilderInterface private iterable $alternatives = []; private ?Node\Expr $client = null; - public function __construct() - { - } - public function withClient(Node\Expr $client): self { $this->client = $client;