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 create capacity for productMedialFile endpoint on Akeneo Loader #59

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Builder/AlternativeLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

public function __construct(
private readonly Builder $capacity,
) {}
) {
}

public function withMerge(Builder $merge): self
{
Expand All @@ -27,13 +28,13 @@
{
return (new IsolatedFuncCallAppendingBuilder(
new Node\Expr\Variable('input'),
array_filter([

Check warning on line 31 in src/Builder/AlternativeLookup.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ } public function getNode() : Node { - return (new IsolatedFuncCallAppendingBuilder(new Node\Expr\Variable('input'), array_filter([$this->capacity->getNode(), $this->merge?->getNode(), new Node\Stmt\Expression(expr: new Node\Expr\MethodCall(var: new Node\Expr\Variable('bucket'), name: new Node\Name('accept'), args: [new Node\Arg(value: new Node\Expr\Variable('output'))]))]), new Node\Expr\Variable('bucket')))->getNode(); + return (new IsolatedFuncCallAppendingBuilder(new Node\Expr\Variable('input'), array_filter([$this->merge?->getNode(), new Node\Stmt\Expression(expr: new Node\Expr\MethodCall(var: new Node\Expr\Variable('bucket'), name: new Node\Name('accept'), args: [new Node\Arg(value: new Node\Expr\Variable('output'))]))]), new Node\Expr\Variable('bucket')))->getNode(); } }
$this->capacity->getNode(),
$this->merge?->getNode(),
new Node\Stmt\Expression(
expr: new Node\Expr\MethodCall(
var: new Node\Expr\Variable('bucket'),
name: new Node\Name('accept'),

Check failure on line 37 in src/Builder/AlternativeLookup.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 37 in src/Builder/AlternativeLookup.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 37 in src/Builder/AlternativeLookup.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.

Check failure on line 37 in src/Builder/AlternativeLookup.php

View workflow job for this annotation

GitHub Actions / phpstan8

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
10 changes: 5 additions & 5 deletions src/Builder/Capacity/Extractor/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

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 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;

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

private function compileSearch(): array

Check failure on line 93 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 93 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.

Check failure on line 93 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.
{
if (null === $this->search) {
return [];
Expand All @@ -104,11 +104,11 @@
];
}

private function compileArguments(): array

Check failure on line 107 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 107 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.

Check failure on line 107 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.
{
$args = [];

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

Check warning on line 111 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) { $args[] = new Node\Arg(value: new Node\Expr\Array_(items: $this->compileSearch(), attributes: ['kind' => Node\Expr\Array_::KIND_SHORT]), name: new Node\Identifier('queryParameters')); } if (null !== $this->code) {
$args[] = new Node\Arg(
value: new Node\Expr\Array_(
items: $this->compileSearch(),
Expand Down Expand Up @@ -141,6 +141,6 @@
);
}

return $args;

Check warning on line 144 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->referenceEntityAttributeCode) { $args[] = new Node\Arg(value: $this->referenceEntityAttributeCode, name: new Node\Identifier('attributeCode')); } - return $args; + return count($args) > 1 ? array_slice($args, 0, 1, true) : $args; } }
}
}
8 changes: 5 additions & 3 deletions src/Builder/Capacity/Extractor/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -50,10 +52,10 @@
name: $this->endpoint
),
name: new Node\Identifier('get'),
args: array_filter(

Check warning on line 55 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 58 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
10 changes: 6 additions & 4 deletions src/Builder/Capacity/Extractor/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -54,12 +56,12 @@
name: $this->endpoint
),
name: new Node\Identifier('listPerPage'),
args: array_filter(

Check warning on line 59 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 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([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 64 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 @@ -73,13 +75,13 @@
),
),
valueVar: new Node\Expr\Variable('item'),
subNodes: [

Check warning on line 78 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 79 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_(
class: new Node\Name\FullyQualified(name: \Kiboko\Component\Bucket\AcceptanceResultBucket::class),
args: [

Check warning on line 84 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' => [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: [])))]]); } private function compileSearch() : array {
new Node\Arg(
new Node\Expr\Variable('item')
),
Expand All @@ -92,7 +94,7 @@
);
}

private function compileSearch(): array

Check failure on line 97 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 97 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.

Check failure on line 97 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.
{
if (null === $this->search) {
return [];
Expand Down
243 changes: 243 additions & 0 deletions src/Builder/Capacity/Loader/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<?php

declare(strict_types=1);

namespace Kiboko\Plugin\Akeneo\Builder\Capacity\Loader;

use Kiboko\Plugin\Akeneo\MissingEndpointException;
use Kiboko\Plugin\Akeneo\MissingParameterException;
use PhpParser\Builder;
use PhpParser\Node;

final class Create implements Builder
{
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
{
$this->endpoint = $endpoint;

return $this;
}

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

return $this;
}

public function withData(Node\Expr $line): self
{
$this->data = $line;

return $this;
}

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

return $this;
}

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

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.');
}
if (null === $this->code) {
throw new MissingParameterException(message: 'Please check your capacity builder, you should have provided a code.');
}
if (null === $this->data) {
throw new MissingParameterException(message: 'Please check your capacity builder, you should have provided some data.');
}

return new Node\Stmt\While_(
cond: new Node\Expr\ConstFetch(
name: new Node\Name('true')
),
stmts: [
new Node\Stmt\TryCatch(
stmts: [
new Node\Stmt\Expression(
expr: new Node\Expr\MethodCall(
new Node\Expr\MethodCall(
var: new Node\Expr\PropertyFetch(
var: new Node\Expr\Variable('this'),
name: new Node\Identifier('client'),
),
name: $this->endpoint,
),
new Node\Identifier('create'),
array_filter([
$this->referenceEntity ? new Node\Arg(value: $this->referenceEntity) : null,
$this->referenceEntityAttribute ? new Node\Arg(value: $this->referenceEntityAttribute) : null,
new Node\Arg(value: $this->code),
new Node\Arg(value: $this->data),
]),
JoMessina marked this conversation as resolved.
Show resolved Hide resolved
),
),
new Node\Stmt\Expression(
expr: new Node\Expr\Assign(
var: new Node\Expr\Variable('line'),
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\Variable('line'),
),
],
),
),
)
),
],
catches: [
new Node\Stmt\Catch_(
types: [
new Node\Name\FullyQualified(
name: \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException::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'),
),
new Node\Expr\ArrayItem(
value: new Node\Expr\MethodCall(
var: new Node\Expr\Variable('exception'),
name: new Node\Identifier('getResponseErrors'),
),
key: new Node\Scalar\String_('errors'),
),
new Node\Expr\ArrayItem(
value: new Node\Expr\Variable('line'),
key: new Node\Scalar\String_('item'),
),
],
attributes: [
'kind' => Node\Expr\Array_::KIND_SHORT,
],
),
),
],
),
),
new Node\Stmt\Expression(
expr: new Node\Expr\Assign(
var: new Node\Expr\Variable('line'),
expr: new Node\Expr\Yield_(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified(
name: \Kiboko\Component\Bucket\RejectionResultBucket::class
),
args: [
new Node\Arg(
value: new Node\Expr\Variable('line'),
),
],
),
),
),
),
],
),
new Node\Stmt\Catch_(
types: [
new Node\Name\FullyQualified(
name: \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'),
),
new Node\Expr\ArrayItem(
value: new Node\Expr\Variable('line'),
key: new Node\Scalar\String_('item'),
),
],
attributes: [
'kind' => Node\Expr\Array_::KIND_SHORT,
],
),
),
],
),
),
new Node\Stmt\Expression(
expr: new Node\Expr\Assign(
var: new Node\Expr\Variable('line'),
expr: new Node\Expr\Yield_(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified(
name: \Kiboko\Component\Bucket\RejectionResultBucket::class
),
args: [
new Node\Arg(
value: new Node\Expr\Variable('line'),
),
],
),
),
),
),
],
),
],
),
],
);
}
}
10 changes: 5 additions & 5 deletions src/Builder/Capacity/Loader/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 4 additions & 4 deletions src/Builder/Capacity/Loader/UpsertList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
10 changes: 6 additions & 4 deletions src/Builder/Capacity/Lookup/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -94,7 +96,7 @@
};
}

private function compileSearch(): array

Check failure on line 99 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 99 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.

Check failure on line 99 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.
{
if (null === $this->search) {
return [];
Expand Down
8 changes: 5 additions & 3 deletions src/Builder/Capacity/Lookup/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -127,7 +129,7 @@
new Node\Stmt\If_(
cond: new Node\Expr\FuncCall(
name: new Node\Name('preg_match'),
args: [

Check failure on line 132 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.

Check failure on line 132 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.
new Node\Arg(new Node\Scalar\String_('/filename="([^"]+)"/')),
new Node\Arg(
new Node\Expr\ArrayDimFetch(
Expand Down
12 changes: 7 additions & 5 deletions src/Builder/Capacity/Lookup/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -68,12 +70,12 @@
args: array_filter(
[
new Node\Arg(
value: $this->identifier,

Check failure on line 73 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 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::compileIdentifierNamedArgument() expects string, string|null given.
),
null !== $this->code ? new Node\Arg(
value: $this->code,
name: $this->compileCodeNamedArgument($this->type),

Check failure on line 78 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 @@ -127,7 +129,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 132 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 132 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 132 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
Loading
Loading