Skip to content

Commit

Permalink
Add expression to return correct format for product association in Pr…
Browse files Browse the repository at this point in the history
…oductMedialFile endpoint
  • Loading branch information
JoMessina committed Apr 29, 2024
1 parent e00122e commit 3179276
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/AkeneoBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function getFunctions(): array
new WithReferenceEntitySimpleOption('withReferenceEntitySimpleOption'),
new WithSimpleOption('withSimpleOption'),
new WithMultipleOption('withMultipleOption'),
new WithProductValueMediaFile('withProductValueMediaFile'),
];
}
}
44 changes: 44 additions & 0 deletions src/WithProductValueMediaFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Kiboko\Component\ExpressionLanguage\Akeneo;

use Symfony\Component\ExpressionLanguage\ExpressionFunction;

final class WithProductValueMediaFile extends ExpressionFunction
{
public function __construct($name)
{
parent::__construct(
$name,
$this->compile(...)->bindTo($this),
$this->evaluate(...)->bindTo($this)
);
}

private function compile(string $code, string $attribute, string $locale = 'null', string $scope = 'null'): string
{
return <<<PHP
([
'identifier' => ({$code}),
'attribute' => ({$attribute}),
'locale' => {$locale},
'scope' => {$scope},
])
PHP;
}

/**
* @return array<int, string>
*/
private function evaluate(array $context, string $code, string $attribute, string $locale = 'null', string $scope = 'null'): array
{
return [

Check failure on line 37 in src/WithProductValueMediaFile.php

View workflow job for this annotation

GitHub Actions / phpstan5

Method Kiboko\Component\ExpressionLanguage\Akeneo\WithProductValueMediaFile::evaluate() should return array<int, string> but returns array<string, string>.

Check failure on line 37 in src/WithProductValueMediaFile.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\ExpressionLanguage\Akeneo\WithProductValueMediaFile::evaluate() should return array<int, string> but returns array<string, string>.
'identifier' => $code,
'attribute' => $attribute,
'locale' => $locale,
'scope' => $scope,
];
}
}

0 comments on commit 3179276

Please sign in to comment.