Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new parameter for endpoint category #60

Merged
merged 9 commits into from
May 28, 2024
39 changes: 38 additions & 1 deletion src/Builder/Capacity/Extractor/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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
{
Expand Down Expand Up @@ -51,6 +52,13 @@
return $this;
}

public function withEnrichedAttributes(?Node\Expr $withEnrichedAttributes): self
{
$this->withEnrichedAttributes = $withEnrichedAttributes;

return $this;
}

public function getNode(): Node
{
if (null === $this->endpoint) {
Expand Down Expand Up @@ -90,7 +98,7 @@
);
}

private function compileSearch(): array

Check failure on line 101 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\All::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 101 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\All::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 101 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\All::compileSearch() return type has no value type specified in iterable type array.
{
if (null === $this->search) {
return [];
Expand All @@ -104,14 +112,26 @@
];
}

private function compileArguments(): array

Check failure on line 115 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\All::compileArguments() return type has no value type specified in iterable type array.

Check failure on line 115 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\All::compileArguments() return type has no value type specified in iterable type array.

Check failure on line 115 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\All::compileArguments() return type has no value type specified in iterable type array.
{
$args = [];

if (null !== $this->search) {

Check warning on line 119 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "NotIdentical": --- Original +++ New @@ @@ private function compileArguments() : array { $args = []; - if (null !== $this->search) { + 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'))]);
$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,
]
Expand Down Expand Up @@ -141,6 +161,23 @@
);
}

if (null !== $this->withEnrichedAttributes && null === $this->search) {

Check warning on line 164 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Identical": --- Original +++ New @@ @@ if (null !== $this->referenceEntityAttributeCode) { $args[] = new Node\Arg(value: $this->referenceEntityAttributeCode, name: new Node\Identifier('attributeCode')); } - if (null !== $this->withEnrichedAttributes && null === $this->search) { + if (null !== $this->withEnrichedAttributes && null !== $this->search) { $args[] = new Node\Arg(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')); } return $args; } }
$args[] = new Node\Arg(
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'),
);
}

return $args;

Check warning on line 181 in src/Builder/Capacity/Extractor/All.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayOneItem": --- Original +++ New @@ @@ if (null !== $this->withEnrichedAttributes && null === $this->search) { $args[] = new Node\Arg(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')); } - return $args; + return count($args) > 1 ? array_slice($args, 0, 1, true) : $args; } }
}
}
4 changes: 0 additions & 4 deletions src/Builder/Capacity/Extractor/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
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;
Expand Down Expand Up @@ -52,10 +48,10 @@
name: $this->endpoint
),
name: new Node\Identifier('get'),
args: array_filter(

Check warning on line 51 in src/Builder/Capacity/Extractor/Get.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "UnwrapArrayFilter": --- Original +++ New @@ @@ if (null === $this->endpoint) { throw new MissingEndpointException(message: 'Please check your capacity builder, you should have selected an endpoint.'); } - return 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(value: 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('get'), args: array_filter([new Node\Arg(value: $this->identifier, name: new Node\Identifier('code'))])), unpack: true)]))); + return 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(value: 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('get'), args: [new Node\Arg(value: $this->identifier, name: new Node\Identifier('code'))]), unpack: true)]))); } }
[
new Node\Arg(
value: $this->identifier,

Check failure on line 54 in src/Builder/Capacity/Extractor/Get.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter $value of class PhpParser\Node\Arg constructor expects PhpParser\Node\Expr, PhpParser\Node\Expr|null given.
name: new Node\Identifier('code'),
),
],
Expand Down
4 changes: 0 additions & 4 deletions src/Builder/Capacity/Extractor/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
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;
Expand Down Expand Up @@ -56,12 +52,12 @@
name: $this->endpoint
),
name: new Node\Identifier('listPerPage'),
args: array_filter(

Check warning on line 55 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "UnwrapArrayFilter": --- Original +++ New @@ @@ 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([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' => [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'))])))]]); + 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: [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' => [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'))])))]]); } private function compileSearch() : array {
[

Check warning on line 56 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ 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([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' => [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'))])))]]); + 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([null !== $this->code ? new Node\Arg(value: $this->code, name: new Node\Identifier('attributeCode')) : null])), valueVar: new Node\Expr\Variable('item'), subNodes: ['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'))])))]]); } private function compileSearch() : array {
new Node\Arg(
value: new Node\Expr\Array_(
items: $this->compileSearch(),
attributes: [

Check warning on line 60 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ 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([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' => [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'))])))]]); + 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([new Node\Arg(value: new Node\Expr\Array_(items: $this->compileSearch(), attributes: []), 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' => [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'))])))]]); } private function compileSearch() : array {
'kind' => Node\Expr\Array_::KIND_SHORT,
]
),
Expand All @@ -75,8 +71,8 @@
),
),
valueVar: new Node\Expr\Variable('item'),
subNodes: [

Check warning on line 74 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ 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([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' => [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'))])))]]); + 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([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: []); } private function compileSearch() : array {
'stmts' => [

Check warning on line 75 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ 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([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' => [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'))])))]]); + 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([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' => []]); } private function compileSearch() : array {
new Node\Stmt\Expression(
expr: new Node\Expr\Yield_(
value: new Node\Expr\New_(
Expand All @@ -94,7 +90,7 @@
);
}

private function compileSearch(): array

Check failure on line 93 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\ListPerPage::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 93 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\ListPerPage::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 93 in src/Builder/Capacity/Extractor/ListPerPage.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Extractor\ListPerPage::compileSearch() return type has no value type specified in iterable type array.
{
if (null === $this->search) {
return [];
Expand Down
4 changes: 0 additions & 4 deletions src/Builder/Capacity/Lookup/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
private ?Node\Expr $code = null;
private string $type = '';

public function __construct()
{
}

public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self
{
$this->endpoint = $endpoint;
Expand Down Expand Up @@ -96,7 +92,7 @@
};
}

private function compileSearch(): array

Check failure on line 95 in src/Builder/Capacity/Lookup/All.php

View workflow job for this annotation

GitHub Actions / phpstan8

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\All::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 95 in src/Builder/Capacity/Lookup/All.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\All::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 95 in src/Builder/Capacity/Lookup/All.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\All::compileSearch() return type has no value type specified in iterable type array.
{
if (null === $this->search) {
return [];
Expand Down
4 changes: 0 additions & 4 deletions src/Builder/Capacity/Lookup/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
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;
Expand Down Expand Up @@ -129,7 +125,7 @@
new Node\Stmt\If_(
cond: new Node\Expr\FuncCall(
name: new Node\Name('preg_match'),
args: [

Check failure on line 128 in src/Builder/Capacity/Lookup/Download.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter $args of class PhpParser\Node\Expr\FuncCall constructor expects array<PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder>, array<int, PhpParser\Node\Arg|PhpParser\Node\Expr\Variable> given.

Check failure on line 128 in src/Builder/Capacity/Lookup/Download.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter $args of class PhpParser\Node\Expr\FuncCall constructor expects array<PhpParser\Node\Arg|PhpParser\Node\VariadicPlaceholder>, array<int, PhpParser\Node\Arg|PhpParser\Node\Expr\Variable> given.
new Node\Arg(new Node\Scalar\String_('/filename="([^"]+)"/')),
new Node\Arg(
new Node\Expr\ArrayDimFetch(
Expand Down
4 changes: 0 additions & 4 deletions src/Builder/Capacity/Lookup/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
private ?Node\Expr $code = null;
private ?string $type = '';

public function __construct()
{
}

public function withEndpoint(Node\Expr|Node\Identifier $endpoint): self
{
$this->endpoint = $endpoint;
Expand Down Expand Up @@ -70,12 +66,12 @@
args: array_filter(
[
new Node\Arg(
value: $this->identifier,

Check failure on line 69 in src/Builder/Capacity/Lookup/Get.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter $value of class PhpParser\Node\Arg constructor expects PhpParser\Node\Expr, PhpParser\Node\Expr|null given.
name: $this->compileIdentifierNamedArgument($this->type),

Check failure on line 70 in src/Builder/Capacity/Lookup/Get.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter #1 $type of method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\Get::compileIdentifierNamedArgument() expects string, string|null given.
),
null !== $this->code ? new Node\Arg(
value: $this->code,
name: $this->compileCodeNamedArgument($this->type),

Check failure on line 74 in src/Builder/Capacity/Lookup/Get.php

View workflow job for this annotation

GitHub Actions / phpstan8

Parameter #1 $type of method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\Get::compileCodeNamedArgument() expects string, string|null given.
) : null,
],
),
Expand Down Expand Up @@ -129,7 +125,7 @@
new Node\Stmt\Expression(
expr: new Node\Expr\MethodCall(
var: new Node\Expr\Variable('bucket'),
name: new Node\Name('reject'),

Check failure on line 128 in src/Builder/Capacity/Lookup/Get.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter $name of class PhpParser\Node\Expr\MethodCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Identifier|string, PhpParser\Node\Name given.

Check failure on line 128 in src/Builder/Capacity/Lookup/Get.php

View workflow job for this annotation

GitHub Actions / phpstan7

Parameter $name of class PhpParser\Node\Expr\MethodCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Identifier|string, PhpParser\Node\Name given.

Check failure on line 128 in src/Builder/Capacity/Lookup/Get.php

View workflow job for this annotation

GitHub Actions / phpstan6

Parameter $name of class PhpParser\Node\Expr\MethodCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Identifier|string, PhpParser\Node\Name given.
args: [
new Node\Arg(
value: new Node\Expr\Variable('input')
Expand Down
4 changes: 0 additions & 4 deletions src/Builder/Capacity/Lookup/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
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;
Expand Down Expand Up @@ -94,7 +90,7 @@
);
}

private function compileSearch(): array

Check failure on line 93 in src/Builder/Capacity/Lookup/ListPerPage.php

View workflow job for this annotation

GitHub Actions / phpstan7

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\ListPerPage::compileSearch() return type has no value type specified in iterable type array.

Check failure on line 93 in src/Builder/Capacity/Lookup/ListPerPage.php

View workflow job for this annotation

GitHub Actions / phpstan6

Method Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup\ListPerPage::compileSearch() return type has no value type specified in iterable type array.
{
if (null === $this->search) {
return [];
Expand Down
4 changes: 0 additions & 4 deletions src/Builder/ConditionalLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
private iterable $alternatives = [];
private ?Node\Expr $client = null;

public function __construct()
{
}

public function withClient(Node\Expr $client): self
{
$this->client = $client;
Expand All @@ -44,7 +40,7 @@

public function addAlternative(Node\Expr $condition, AlternativeLookup $lookup): self
{
$this->alternatives[] = [$condition, $lookup];

Check failure on line 43 in src/Builder/ConditionalLookup.php

View workflow job for this annotation

GitHub Actions / phpstan7

Cannot access an offset on iterable<array<int, Kiboko\Plugin\Akeneo\Builder\AlternativeLookup|PhpParser\Node\Expr>>.

return $this;
}
Expand Down Expand Up @@ -93,7 +89,7 @@
'elseifs' => array_map(
fn (Node\Expr $condition, AlternativeLookup $lookup) => new Node\Stmt\ElseIf_(
cond: $condition,
stmts: $this->compileAlternative($lookup)

Check failure on line 92 in src/Builder/ConditionalLookup.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter $stmts of class PhpParser\Node\Stmt\ElseIf_ constructor expects array<PhpParser\Node\Stmt>, array<int, PhpParser\Node> given.

Check failure on line 92 in src/Builder/ConditionalLookup.php

View workflow job for this annotation

GitHub Actions / phpstan6

Parameter $stmts of class PhpParser\Node\Stmt\ElseIf_ constructor expects array<PhpParser\Node\Stmt>, array<int, PhpParser\Node> given.
),
array_column($alternatives, 0),
array_column($alternatives, 1)
Expand All @@ -103,7 +99,7 @@
new Node\Stmt\Expression(
expr: new Node\Expr\MethodCall(
var: new Node\Expr\Variable('bucket'),
name: new Node\Name('accept'),

Check failure on line 102 in src/Builder/ConditionalLookup.php

View workflow job for this annotation

GitHub Actions / phpstan5

Parameter $name of class PhpParser\Node\Expr\MethodCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Identifier|string, PhpParser\Node\Name given.

Check failure on line 102 in src/Builder/ConditionalLookup.php

View workflow job for this annotation

GitHub Actions / phpstan6

Parameter $name of class PhpParser\Node\Expr\MethodCall constructor expects PhpParser\Node\Expr|PhpParser\Node\Identifier|string, PhpParser\Node\Name given.
args: [
new Node\Arg(
value: new Node\Expr\Variable('output')
Expand Down
4 changes: 4 additions & 0 deletions src/Capacity/Extractor/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function getBuilder(array $config): Builder
$builder->withSearch($this->compileFilters(...$config['search']));
}

if (isset($config['with_enriched_attributes']) && 'category' === $config['type']) {
$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']));
}
Expand Down
14 changes: 14 additions & 0 deletions src/Configuration/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -238,6 +246,12 @@ public function getConfigTreeBuilder(): Config\Definition\Builder\TreeBuilder
->then(asExpression())
->end()
->end()
->booleanNode('with_enriched_attributes')
->validate()
->ifTrue(isExpression())
->then(asExpression())
->end()
->end()
->append((new Search())->getConfigTreeBuilder()->getRootNode())
->end()
;
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/Configuration/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
Loading