diff --git a/infection.json.dist b/infection.json.dist index 59d2346..1dd827b 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -20,6 +20,6 @@ "@default": true }, "testFramework":"phpunit", - "minMsi": 30, - "minCoveredMsi": 40 + "minMsi": 50, + "minCoveredMsi": 60 } diff --git a/rector.php b/rector.php index de7e4d1..cac436a 100644 --- a/rector.php +++ b/rector.php @@ -14,10 +14,8 @@ __DIR__ . '/tests', ]); - // register a single rule $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); - // define sets of rules $rectorConfig->sets([ LevelSetList::UP_TO_PHP_82, PHPUnitLevelSetList::UP_TO_PHPUNIT_100, diff --git a/src/Builder/Capacity/Extractor/ListPerPage.php b/src/Builder/Capacity/Extractor/ListPerPage.php index 9ffed46..5d0705f 100644 --- a/src/Builder/Capacity/Extractor/ListPerPage.php +++ b/src/Builder/Capacity/Extractor/ListPerPage.php @@ -13,6 +13,7 @@ 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 null|string $type = null; public function __construct() { @@ -32,13 +33,20 @@ public function withSearch(Node\Expr $search): self return $this; } - public function withCode(Node\Expr $code): self + public function withCode(?Node\Expr $code): self { $this->code = $code; return $this; } + public function withType(string $type): self + { + $this->type = $type; + + return $this; + } + public function getNode(): Node { if (null === $this->endpoint) { @@ -69,7 +77,7 @@ public function getNode(): Node ), null !== $this->code ? new Node\Arg( value: $this->code, - name: new Node\Identifier('attributeCode'), + name: $this->compileCodeNamedArgument($this->type), ) : null, ], ), @@ -90,7 +98,7 @@ class: new Node\Name\FullyQualified(name: \Kiboko\Component\Bucket\AcceptanceRes ), ), ], - ] + ], ); } @@ -107,4 +115,12 @@ private function compileSearch(): array ), ]; } + + private function compileCodeNamedArgument(string $type): Node\Identifier + { + return match ($type) { + 'assetManager' => new Node\Identifier('assetFamilyCode'), + default => new Node\Identifier('attributeCode') + }; + } } diff --git a/src/Builder/Capacity/Loader/Upsert.php b/src/Builder/Capacity/Loader/Upsert.php index 52501f8..da32f5b 100644 --- a/src/Builder/Capacity/Loader/Upsert.php +++ b/src/Builder/Capacity/Loader/Upsert.php @@ -109,7 +109,7 @@ class: new Node\Name\FullyQualified(name: \Kiboko\Component\Bucket\AcceptanceRes new Node\Stmt\Catch_( types: [ new Node\Name\FullyQualified( - name: \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException::class + name: \Akeneo\Pim\ApiClient\Exception\HttpException::class, ), ], var: new Node\Expr\Variable('exception'), diff --git a/src/Builder/Capacity/Lookup/All.php b/src/Builder/Capacity/Lookup/All.php index c6e1104..36231c2 100644 --- a/src/Builder/Capacity/Lookup/All.php +++ b/src/Builder/Capacity/Lookup/All.php @@ -4,6 +4,7 @@ namespace Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup; +use Kiboko\Component\SatelliteToolbox\Builder\IsolatedValueAppendingBuilder; use Kiboko\Plugin\Akeneo\MissingEndpointException; use PhpParser\Builder; use PhpParser\Node; @@ -33,7 +34,7 @@ public function withSearch(Node\Expr $search): self return $this; } - public function withCode(Node\Expr $code): self + public function withCode(?Node\Expr $code): self { $this->code = $code; @@ -53,47 +54,122 @@ public function getNode(): Node throw new MissingEndpointException(message: 'Please check your capacity builder, you should have selected an endpoint.'); } - return new Node\Stmt\Expression( - new Node\Expr\Assign( - var: new Node\Expr\Variable('lookup'), - expr: new Node\Expr\MethodCall( - var: new Node\Expr\MethodCall( - var: new Node\Expr\PropertyFetch( - var: new Node\Expr\Variable('this'), - name: new Node\Identifier('client') - ), - name: $this->endpoint - ), - name: new Node\Identifier('all'), - args: array_filter( - [ + return (new IsolatedValueAppendingBuilder( + new Node\Expr\Variable('input'), + new Node\Expr\Variable('lookup'), + array_filter([ + $this->code ? new Node\Stmt\If_( + cond: new Node\Expr\FuncCall( + name: new Node\Name('is_null'), + args: [ new Node\Arg( - value: new Node\Expr\Array_( - items: $this->compileSearch(), - attributes: [ - 'kind' => Node\Expr\Array_::KIND_SHORT, - ] - ), - name: new Node\Identifier('queryParameters'), - ), - null !== $this->code ? new Node\Arg( value: $this->code, - name: $this->compileCodeNamedArgument($this->type), - ) : null, + ), ], ), + subNodes: [ + 'stmts' => [ + new Node\Stmt\Return_( + expr: new Node\Expr\ConstFetch( + name: new Node\Name(name: 'null'), + ), + ), + ], + ], + ) : null, + new Node\Stmt\TryCatch( + stmts: [ + new Node\Stmt\Expression( + expr: new Node\Expr\Assign( + var: new Node\Expr\Variable('items'), + expr: new Node\Expr\MethodCall( + var: new Node\Expr\MethodCall( + var: new Node\Expr\PropertyFetch( + var: new Node\Expr\Variable('this'), + name: new Node\Identifier('client'), + ), + name: $this->endpoint + ), + name: new Node\Identifier('all'), + args: array_filter( + [ + new Node\Arg( + value: new Node\Expr\Array_( + items: $this->compileSearch(), + attributes: [ + 'kind' => Node\Expr\Array_::KIND_SHORT, + ] + ), + name: new Node\Identifier('queryParameters'), + ), + null !== $this->code ? new Node\Arg( + value: $this->code, + name: $this->compileCodeNamedArgument($this->type), + ) : null, + ], + ), + ), + ), + ), + ], + catches: [ + new Node\Stmt\Catch_( + types: [ + new Node\Name\FullyQualified(\Akeneo\Pim\ApiClient\Exception\HttpException::class), + ], + var: new Node\Expr\Variable('exception'), + stmts: [ + new Node\Stmt\Expression( + expr: new Node\Expr\MethodCall( + var: new Node\Expr\PropertyFetch( + var: new Node\Expr\Variable('this'), + name: 'logger', + ), + name: new Node\Identifier('error'), + args: [ + new Node\Arg( + value: new Node\Expr\MethodCall( + var: new Node\Expr\Variable('exception'), + name: new Node\Identifier('getMessage'), + ), + ), + new Node\Arg( + value: new Node\Expr\Array_( + items: [ + new Node\Expr\ArrayItem( + value: new Node\Expr\Variable('exception'), + key: new Node\Scalar\String_('exception'), + ), + ], + attributes: [ + 'kind' => Node\Expr\Array_::KIND_SHORT, + ], + ), + ), + ], + ), + ), + new Node\Stmt\Expression( + expr: new Node\Expr\MethodCall( + var: new Node\Expr\Variable('bucket'), + name: new Node\Identifier('reject'), + args: [ + new Node\Arg( + new Node\Expr\Variable('input'), + ), + ], + ) + ), + ], + ), + ], ), - ), - ); - } - - private function compileCodeNamedArgument(string $type): Node\Identifier - { - return match ($type) { - 'referenceEntityRecord' => new Node\Identifier('referenceEntityCode'), - 'assetManager' => new Node\Identifier('assetFamilyCode'), - default => new Node\Identifier('attributeCode') - }; + new Node\Stmt\Return_( + expr: new Node\Expr\Variable('items'), + ), + ]), + new Node\Expr\Variable('bucket') + ))->getNode(); } private function compileSearch(): array @@ -109,4 +185,12 @@ private function compileSearch(): array ), ]; } + + private function compileCodeNamedArgument(string $type): Node\Identifier + { + return match ($type) { + 'assetManager' => new Node\Identifier('assetFamilyCode'), + default => new Node\Identifier('attributeCode') + }; + } } diff --git a/src/Builder/Capacity/Lookup/Get.php b/src/Builder/Capacity/Lookup/Get.php index 9a3c138..0519bdc 100644 --- a/src/Builder/Capacity/Lookup/Get.php +++ b/src/Builder/Capacity/Lookup/Get.php @@ -144,7 +144,7 @@ public function getNode(): Node ); } - private function compileCodeNamedArgument(string $type): Node\Identifier + private function compileCodeNamedArgument(?string $type): Node\Identifier { return match ($type) { 'referenceEntityRecord' => new Node\Identifier('referenceEntityCode'), @@ -153,7 +153,7 @@ private function compileCodeNamedArgument(string $type): Node\Identifier }; } - private function compileIdentifierNamedArgument(string $type): Node\Identifier + private function compileIdentifierNamedArgument(?string $type): Node\Identifier { return match ($type) { 'referenceEntityRecord' => new Node\Identifier('recordCode'), diff --git a/src/Builder/Capacity/Lookup/ListPerPage.php b/src/Builder/Capacity/Lookup/ListPerPage.php index f8ee225..47df875 100644 --- a/src/Builder/Capacity/Lookup/ListPerPage.php +++ b/src/Builder/Capacity/Lookup/ListPerPage.php @@ -4,6 +4,7 @@ namespace Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup; +use Kiboko\Component\SatelliteToolbox\Builder\IsolatedValueAppendingBuilder; use Kiboko\Plugin\Akeneo\MissingEndpointException; use PhpParser\Builder; use PhpParser\Node; @@ -13,6 +14,7 @@ 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 null|string $type = null; public function __construct() { @@ -32,66 +34,142 @@ public function withSearch(Node\Expr $search): self return $this; } - public function withCode(Node\Expr $code): self + public function withCode(?Node\Expr $code): self { $this->code = $code; return $this; } + public function withType(string $type): self + { + $this->type = $type; + + return $this; + } + public function getNode(): Node { if (null === $this->endpoint) { throw new MissingEndpointException(message: 'Please check your capacity builder, you should have selected an endpoint.'); } - return - new Node\Stmt\Foreach_( - expr: new Node\Expr\MethodCall( - var: new Node\Expr\MethodCall( - var: new Node\Expr\PropertyFetch( - var: new Node\Expr\Variable('this'), - name: new Node\Identifier('client') - ), - name: $this->endpoint - ), - name: new Node\Identifier('listPerPage'), - args: array_filter( - [ + return (new IsolatedValueAppendingBuilder( + new Node\Expr\Variable('input'), + new Node\Expr\Variable('lookup'), + array_filter([ + $this->code ? new Node\Stmt\If_( + cond: new Node\Expr\FuncCall( + name: new Node\Name('is_null'), + args: [ new Node\Arg( - value: new Node\Expr\Array_( - items: $this->compileSearch(), - attributes: [ - 'kind' => Node\Expr\Array_::KIND_SHORT, - ] - ), - name: new Node\Identifier('queryParameters'), - ), - null !== $this->code ? new Node\Arg( value: $this->code, - name: new Node\Identifier('attributeCode'), - ) : null, + ), ], ), - ), - valueVar: new Node\Expr\Variable('item'), - subNodes: [ - 'stmts' => [ + subNodes: [ + 'stmts' => [ + new Node\Stmt\Return_( + expr: new Node\Expr\ConstFetch( + name: new Node\Name(name: 'null'), + ), + ), + ], + ], + ) : null, + new Node\Stmt\TryCatch( + stmts: [ new Node\Stmt\Expression( - expr: new Node\Expr\Yield_( - value: new Node\Expr\New_( - class: new Node\Name\FullyQualified(name: \Kiboko\Component\Bucket\AcceptanceResultBucket::class), - args: [ - new Node\Arg( - new Node\Expr\Variable('item') + expr: new Node\Expr\Assign( + var: new Node\Expr\Variable('items'), + expr: new Node\Expr\MethodCall( + var: new Node\Expr\MethodCall( + var: new Node\Expr\PropertyFetch( + var: new Node\Expr\Variable('this'), + name: new Node\Identifier('client'), ), - ], + name: $this->endpoint + ), + name: new Node\Identifier('listPerPage'), + args: array_filter( + [ + new Node\Arg( + value: new Node\Expr\Array_( + items: $this->compileSearch(), + attributes: [ + 'kind' => Node\Expr\Array_::KIND_SHORT, + ] + ), + name: new Node\Identifier('queryParameters'), + ), + null !== $this->code ? new Node\Arg( + value: $this->code, + name: $this->compileCodeNamedArgument($this->type), + ) : null, + ], + ), ), ), ), ], - ] - ); + catches: [ + new Node\Stmt\Catch_( + types: [ + new Node\Name\FullyQualified(\Akeneo\Pim\ApiClient\Exception\HttpException::class), + ], + var: new Node\Expr\Variable('exception'), + stmts: [ + new Node\Stmt\Expression( + expr: new Node\Expr\MethodCall( + var: new Node\Expr\PropertyFetch( + var: new Node\Expr\Variable('this'), + name: 'logger', + ), + name: new Node\Identifier('error'), + args: [ + new Node\Arg( + value: new Node\Expr\MethodCall( + var: new Node\Expr\Variable('exception'), + name: new Node\Identifier('getMessage'), + ), + ), + new Node\Arg( + value: new Node\Expr\Array_( + items: [ + new Node\Expr\ArrayItem( + value: new Node\Expr\Variable('exception'), + key: new Node\Scalar\String_('exception'), + ), + ], + attributes: [ + 'kind' => Node\Expr\Array_::KIND_SHORT, + ], + ), + ), + ], + ), + ), + new Node\Stmt\Expression( + expr: new Node\Expr\MethodCall( + var: new Node\Expr\Variable('bucket'), + name: new Node\Identifier('reject'), + args: [ + new Node\Arg( + new Node\Expr\Variable('input'), + ), + ], + ) + ), + ], + ), + ], + ), + new Node\Stmt\Return_( + expr: new Node\Expr\Variable('items'), + ), + ]), + new Node\Expr\Variable('bucket') + ))->getNode(); } private function compileSearch(): array @@ -107,4 +185,12 @@ private function compileSearch(): array ), ]; } + + private function compileCodeNamedArgument(string $type): Node\Identifier + { + return match ($type) { + 'assetManager' => new Node\Identifier('assetFamilyCode'), + default => new Node\Identifier('attributeCode') + }; + } } diff --git a/src/Capacity/Extractor/All.php b/src/Capacity/Extractor/All.php index 0b73402..171cd91 100644 --- a/src/Capacity/Extractor/All.php +++ b/src/Capacity/Extractor/All.php @@ -10,7 +10,6 @@ use PhpParser\Node; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue; use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression; final class All implements Akeneo\Capacity\CapacityInterface @@ -43,6 +42,7 @@ final class All implements Akeneo\Capacity\CapacityInterface 'referenceEntityAttributeOption', 'referenceEntity', 'assetManager', + 'assetMediaFile', ]; private static array $unaryOperators = [ @@ -79,11 +79,11 @@ private function compileFilters(array ...$filters): Node\Expr } $builder->addFilter( - field: compileValue($this->interpreter, $filter['field']), - operator: compileValue($this->interpreter, $filter['operator']), - value: \array_key_exists('value', $filter) ? compileValue($this->interpreter, $filter['value']) : null, - scope: \array_key_exists('scope', $filter) ? compileValue($this->interpreter, $filter['scope']) : null, - locale: \array_key_exists('locale', $filter) ? compileValue($this->interpreter, $filter['locale']) : null + field: compileValueWhenExpression($this->interpreter, $filter['field']), + operator: compileValueWhenExpression($this->interpreter, $filter['operator']), + value: \array_key_exists('value', $filter) ? compileValueWhenExpression($this->interpreter, $filter['value']) : null, + scope: \array_key_exists('scope', $filter) ? compileValueWhenExpression($this->interpreter, $filter['scope']) : null, + locale: \array_key_exists('locale', $filter) ? compileValueWhenExpression($this->interpreter, $filter['locale']) : null ); } @@ -101,7 +101,9 @@ public function getBuilder(array $config): Builder $builder->withSearch($this->compileFilters(...$config['search'])); } - if (\in_array($config['type'], ['attributeOption', 'assetManager', 'referenceEntityRecord']) && \array_key_exists('code', $config)) { + if (\in_array($config['type'], ['attributeOption', 'assetManager', 'assetAttribute', 'assetAttributeOption', 'familyVariant', 'referenceEntityAttribute', 'referenceEntityAttributeOption', 'referenceEntityRecord']) + && \array_key_exists('code', $config) + ) { $builder->withCode(compileValueWhenExpression($this->interpreter, $config['code'])); } diff --git a/src/Capacity/Extractor/ListPerPage.php b/src/Capacity/Extractor/ListPerPage.php index 644d94b..ac39648 100644 --- a/src/Capacity/Extractor/ListPerPage.php +++ b/src/Capacity/Extractor/ListPerPage.php @@ -10,7 +10,7 @@ use PhpParser\Node; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue; +use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression; final class ListPerPage implements Akeneo\Capacity\CapacityInterface { @@ -41,6 +41,8 @@ final class ListPerPage implements Akeneo\Capacity\CapacityInterface 'referenceEntityAttribute', 'referenceEntityAttributeOption', 'referenceEntity', + 'assetManager', + 'assetMediaFile', ]; private static array $unaryOperators = [ @@ -77,11 +79,11 @@ private function compileFilters(array ...$filters): Node\Expr } $builder->addFilter( - field: compileValue($this->interpreter, $filter['field']), - operator: compileValue($this->interpreter, $filter['operator']), - value: \array_key_exists('value', $filter) ? compileValue($this->interpreter, $filter['value']) : null, - scope: \array_key_exists('scope', $filter) ? compileValue($this->interpreter, $filter['scope']) : null, - locale: \array_key_exists('locale', $filter) ? compileValue($this->interpreter, $filter['locale']) : null + field: compileValueWhenExpression($this->interpreter, $filter['field']), + operator: compileValueWhenExpression($this->interpreter, $filter['operator']), + value: \array_key_exists('value', $filter) ? compileValueWhenExpression($this->interpreter, $filter['value']) : null, + scope: \array_key_exists('scope', $filter) ? compileValueWhenExpression($this->interpreter, $filter['scope']) : null, + locale: \array_key_exists('locale', $filter) ? compileValueWhenExpression($this->interpreter, $filter['locale']) : null ); } @@ -92,16 +94,17 @@ public function getBuilder(array $config): Builder { $builder = (new Akeneo\Builder\Capacity\Extractor\ListPerPage()) ->withEndpoint(new Node\Identifier(sprintf('get%sApi', ucfirst((string) $config['type'])))) + ->withType($config['type']) ; if (isset($config['search']) && \is_array($config['search'])) { $builder->withSearch($this->compileFilters(...$config['search'])); } - if (\in_array($config['type'], ['attributeOption']) + if (\in_array($config['type'], ['attributeOption', 'assetManager', 'assetAttribute', 'assetAttributeOption', 'familyVariant', 'referenceEntityAttribute', 'referenceEntityAttributeOption', 'referenceEntityRecord']) && \array_key_exists('code', $config) ) { - $builder->withCode(compileValue($this->interpreter, $config['code'])); + $builder->withCode(compileValueWhenExpression($this->interpreter, $config['code'])); } return $builder; diff --git a/src/Capacity/Lookup/All.php b/src/Capacity/Lookup/All.php index 2ac7f6f..3ab4cc4 100644 --- a/src/Capacity/Lookup/All.php +++ b/src/Capacity/Lookup/All.php @@ -42,6 +42,7 @@ final class All implements Akeneo\Capacity\CapacityInterface 'referenceEntityAttributeOption', 'referenceEntity', 'assetManager', + 'assetMediaFile', ]; private static array $unaryOperators = [ @@ -92,15 +93,17 @@ private function compileFilters(array ...$filters): Node\Expr public function getBuilder(array $config): Builder { $builder = (new Akeneo\Builder\Capacity\Lookup\All()) - ->withType((string) $config['type']) ->withEndpoint(new Node\Identifier(sprintf('get%sApi', ucfirst((string) $config['type'])))) + ->withType($config['type']) ; if (isset($config['search']) && \is_array($config['search'])) { $builder->withSearch($this->compileFilters(...$config['search'])); } - if (\in_array($config['type'], ['attributeOption', 'assetManager', 'referenceEntityRecord']) && \array_key_exists('code', $config)) { + if (\in_array($config['type'], ['attributeOption', 'assetManager', 'assetAttribute', 'assetAttributeOption', 'familyVariant', 'referenceEntityAttribute', 'referenceEntityAttributeOption', 'referenceEntityRecord']) + && \array_key_exists('code', $config) + ) { $builder->withCode(compileValueWhenExpression($this->interpreter, $config['code'])); } diff --git a/src/Capacity/Lookup/Download.php b/src/Capacity/Lookup/Download.php index fa46a6c..c9b9bc7 100644 --- a/src/Capacity/Lookup/Download.php +++ b/src/Capacity/Lookup/Download.php @@ -10,7 +10,7 @@ use PhpParser\Node; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue; +use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression; final class Download implements Akeneo\Capacity\CapacityInterface { @@ -43,7 +43,7 @@ public function getBuilder(array $config): Builder if (!\array_key_exists('file', $config)) { throw new Configurator\InvalidConfigurationException('The configuration option "file" should be defined.'); } - $builder->withFile(compileValue($this->interpreter, $config['file'])); + $builder->withFile(compileValueWhenExpression($this->interpreter, $config['file'])); return $builder; } diff --git a/src/Capacity/Lookup/ListPerPage.php b/src/Capacity/Lookup/ListPerPage.php index 4f02b46..dc37f1e 100644 --- a/src/Capacity/Lookup/ListPerPage.php +++ b/src/Capacity/Lookup/ListPerPage.php @@ -10,7 +10,7 @@ use PhpParser\Node; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use function Kiboko\Component\SatelliteToolbox\Configuration\compileValue; +use function Kiboko\Component\SatelliteToolbox\Configuration\compileValueWhenExpression; final class ListPerPage implements Akeneo\Capacity\CapacityInterface { @@ -41,6 +41,7 @@ final class ListPerPage implements Akeneo\Capacity\CapacityInterface 'referenceEntityAttribute', 'referenceEntityAttributeOption', 'referenceEntity', + 'assetManager', ]; private static array $unaryOperators = [ @@ -77,11 +78,11 @@ private function compileFilters(array ...$filters): Node\Expr } $builder->addFilter( - field: compileValue($this->interpreter, $filter['field']), - operator: compileValue($this->interpreter, $filter['operator']), - value: \array_key_exists('value', $filter) ? compileValue($this->interpreter, $filter['value']) : null, - scope: \array_key_exists('scope', $filter) ? compileValue($this->interpreter, $filter['scope']) : null, - locale: \array_key_exists('locale', $filter) ? compileValue($this->interpreter, $filter['locale']) : null + field: compileValueWhenExpression($this->interpreter, $filter['field']), + operator: compileValueWhenExpression($this->interpreter, $filter['operator']), + value: \array_key_exists('value', $filter) ? compileValueWhenExpression($this->interpreter, $filter['value']) : null, + scope: \array_key_exists('scope', $filter) ? compileValueWhenExpression($this->interpreter, $filter['scope']) : null, + locale: \array_key_exists('locale', $filter) ? compileValueWhenExpression($this->interpreter, $filter['locale']) : null ); } @@ -92,16 +93,17 @@ public function getBuilder(array $config): Builder { $builder = (new Akeneo\Builder\Capacity\Lookup\ListPerPage()) ->withEndpoint(new Node\Identifier(sprintf('get%sApi', ucfirst((string) $config['type'])))) + ->withType($config['type']) ; if (isset($config['search']) && \is_array($config['search'])) { $builder->withSearch($this->compileFilters(...$config['search'])); } - if (\in_array($config['type'], ['attributeOption']) + if (\in_array($config['type'], ['attributeOption', 'assetManager', 'assetAttribute', 'assetAttributeOption', 'familyVariant', 'referenceEntityAttribute', 'referenceEntityAttributeOption', 'referenceEntityRecord']) && \array_key_exists('code', $config) ) { - $builder->withCode(compileValue($this->interpreter, $config['code'])); + $builder->withCode(compileValueWhenExpression($this->interpreter, $config['code'])); } return $builder; diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index 3e2c7db..2ed1e60 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -159,14 +159,14 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder ->end() ->validate() ->ifTrue(fn ($data) => \array_key_exists('code', $data) - && \array_key_exists('type', $data) - && !\in_array($data['type'], ['attributeOption', 'referenceEntityRecord', 'assetManager'], true)) + && \array_key_exists('type', $data) + && !\in_array($data['type'], ['attributeOption', 'referenceEntityRecord', 'assetManager'], true)) ->thenInvalid('The code option should only be used with the "attributeOption" and "assetManager" endpoints.') ->end() ->validate() ->ifTrue(fn ($data) => \array_key_exists('file', $data) - && \array_key_exists('type', $data) - && !\in_array($data['type'], ['productMediaFile', 'assetMediaFile'], true)) + && \array_key_exists('type', $data) + && !\in_array($data['type'], ['productMediaFile', 'assetMediaFile'], true)) ->thenInvalid('The file option should only be used with the "productMediaFile" endpoint.') ->end() ->validate() diff --git a/src/Configuration/Loader.php b/src/Configuration/Loader.php index 1efcc9c..994709c 100644 --- a/src/Configuration/Loader.php +++ b/src/Configuration/Loader.php @@ -225,13 +225,13 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui ->thenInvalid('The attribute_code option should be used with the "attributeOption" endpoint.') ->end() ->children() - ->scalarNode('type') - ->isRequired() - ->validate() - ->ifNotInArray(array_keys(self::$endpoints)) - ->thenInvalid( - sprintf('the value should be one of [%s]', implode(', ', array_keys(self::$endpoints))) - ) + ->scalarNode('type') + ->isRequired() + ->validate() + ->ifNotInArray(array_keys(self::$endpoints)) + ->thenInvalid( + sprintf('the value should be one of [%s]', implode(', ', array_keys(self::$endpoints))) + ) ->end() ->end() ->scalarNode('method')->end() diff --git a/src/Configuration/Lookup.php b/src/Configuration/Lookup.php index 41cbab5..43ec0ac 100644 --- a/src/Configuration/Lookup.php +++ b/src/Configuration/Lookup.php @@ -236,14 +236,14 @@ private function getConditionalTreeBuilder(): Config\Definition\Builder\TreeBuil ->end() ->validate() ->ifTrue(fn ($data) => \array_key_exists('code', $data) - && \array_key_exists('type', $data) - && !\in_array($data['type'], ['attributeOption', 'referenceEntityRecord', 'assetManager'], true)) + && \array_key_exists('type', $data) + && !\in_array($data['type'], ['attributeOption', 'referenceEntityRecord', 'assetManager'], true)) ->thenInvalid('The code option should only be used with the "attributeOption", "referenceEntityRecord" and "assetManager" endpoints.') ->end() ->validate() ->ifTrue(fn ($data) => \array_key_exists('file', $data) - && \array_key_exists('type', $data) - && !\in_array($data['type'], ['productMediaFile', 'assetMediaFile'], true)) + && \array_key_exists('type', $data) + && !\in_array($data['type'], ['productMediaFile', 'assetMediaFile'], true)) ->thenInvalid('The file option should only be used with the "productMediaFile" and "assetMediaFile" endpoints.') ->end() ->validate() 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); } }