From e00122e5933b33779463df859fdd75b417e47016 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 24 Apr 2024 17:16:45 +0200 Subject: [PATCH 1/5] remove a static on multiple option expression --- src/WithMultipleOption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WithMultipleOption.php b/src/WithMultipleOption.php index 8466408..f2e5cdd 100644 --- a/src/WithMultipleOption.php +++ b/src/WithMultipleOption.php @@ -23,7 +23,7 @@ private function compile(string $codes, string $attribute, string $labels, strin (function() use(\$input) { \$linkedData = array_map( function (string \$code) use(\$input) { - static \$labels = {$labels}; + \$labels = {$labels}; return [ 'attribute' => {$attribute}, From 317927610a20d6a9cc0684e4c2d1295f94960450 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 29 Apr 2024 12:34:19 +0200 Subject: [PATCH 2/5] Add expression to return correct format for product association in ProductMedialFile endpoint --- src/AkeneoBuilderProvider.php | 1 + src/WithProductValueMediaFile.php | 44 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/WithProductValueMediaFile.php diff --git a/src/AkeneoBuilderProvider.php b/src/AkeneoBuilderProvider.php index a6f2905..08029e8 100644 --- a/src/AkeneoBuilderProvider.php +++ b/src/AkeneoBuilderProvider.php @@ -17,6 +17,7 @@ public function getFunctions(): array new WithReferenceEntitySimpleOption('withReferenceEntitySimpleOption'), new WithSimpleOption('withSimpleOption'), new WithMultipleOption('withMultipleOption'), + new WithProductValueMediaFile('withProductValueMediaFile'), ]; } } diff --git a/src/WithProductValueMediaFile.php b/src/WithProductValueMediaFile.php new file mode 100644 index 0000000..2c82c3a --- /dev/null +++ b/src/WithProductValueMediaFile.php @@ -0,0 +1,44 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $code, string $attribute, string $locale = 'null', string $scope = 'null'): string + { + return << ({$code}), + 'attribute' => ({$attribute}), + 'locale' => {$locale}, + 'scope' => {$scope}, + ]) + PHP; + } + + /** + * @return array + */ + private function evaluate(array $context, string $code, string $attribute, string $locale = 'null', string $scope = 'null'): array + { + return [ + 'identifier' => $code, + 'attribute' => $attribute, + 'locale' => $locale, + 'scope' => $scope, + ]; + } +} From 8e9e6e91a24e8ad216529a1da829612a64d3d409 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 30 Apr 2024 11:47:34 +0200 Subject: [PATCH 3/5] remove useless parenthesis on MediaFile expression --- src/WithProductValueMediaFile.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/WithProductValueMediaFile.php b/src/WithProductValueMediaFile.php index 2c82c3a..fedec2f 100644 --- a/src/WithProductValueMediaFile.php +++ b/src/WithProductValueMediaFile.php @@ -20,12 +20,12 @@ public function __construct($name) private function compile(string $code, string $attribute, string $locale = 'null', string $scope = 'null'): string { return << ({$code}), - 'attribute' => ({$attribute}), + [ + 'identifier' => {$code}, + 'attribute' => {$attribute}, 'locale' => {$locale}, 'scope' => {$scope}, - ]) + ] PHP; } From 753125d59303aa8b92460f39d6e354e6559e0b02 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 13 Jun 2024 17:17:05 +0200 Subject: [PATCH 4/5] cs-fixer fix and phpstan analyse --- src/DateTime.php | 4 ++-- src/DateTimeZone.php | 4 ++-- src/FormatMetric.php | 2 +- src/MetricAmount.php | 2 +- src/MetricUnit.php | 2 +- src/WithMultipleOption.php | 2 +- src/WithProductValueMediaFile.php | 2 +- src/WithReferenceEntitySimpleOption.php | 2 +- src/WithReferenceEntityValue.php | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DateTime.php b/src/DateTime.php index 67220c9..be90f60 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -17,7 +17,7 @@ public function __construct($name) ); } - private function compile(string $date, string|null $format = null): string + private function compile(string $date, ?string $format = null): string { if (null === $format) { return sprintf('new \DateTimeImmutable(%s, new \DateTimeZone("UTC"))', $date); @@ -26,7 +26,7 @@ private function compile(string $date, string|null $format = null): string return sprintf('\DateTimeImmutable::createFromFormat(%s, %s, new \DateTimeZone("UTC"))', $date, $format); } - private function evaluate(array $context, string $date, string|null $format = null): \DateTimeInterface + private function evaluate(array $context, string $date, ?string $format = null): \DateTimeInterface { if (null === $format) { return new \DateTimeImmutable($date, new \DateTimeZone('UTC')); diff --git a/src/DateTimeZone.php b/src/DateTimeZone.php index 9d0392c..6cf0335 100644 --- a/src/DateTimeZone.php +++ b/src/DateTimeZone.php @@ -17,7 +17,7 @@ public function __construct($name) ); } - private function compile(string $date, string $zone, string|null $format = null): string + private function compile(string $date, string $zone, ?string $format = null): string { if (null === $format) { return sprintf('new \DateTimeImmutable(%s, new \DateTimeZone(%s))', $date, $zone); @@ -26,7 +26,7 @@ private function compile(string $date, string $zone, string|null $format = null) return sprintf('\DateTimeImmutable::createFromFormat(%s, %s, new \DateTimeZone(%s))', $date, $format, $zone); } - private function evaluate(array $context, string $date, string $zone, string|null $format = null): \DateTimeInterface + private function evaluate(array $context, string $date, string $zone, ?string $format = null): \DateTimeInterface { if (null === $format) { return new \DateTimeImmutable($date, new \DateTimeZone($zone)); diff --git a/src/FormatMetric.php b/src/FormatMetric.php index 3232489..1ffc42a 100644 --- a/src/FormatMetric.php +++ b/src/FormatMetric.php @@ -171,7 +171,7 @@ private function compile($attribute, $locale): string PHP; } - private function evaluate(array $context, array $attribut, string $locale): string|null + private function evaluate(array $context, array $attribut, string $locale): ?string { return !\is_array($attribut) || !\array_key_exists('amount', $attribut) || !\array_key_exists('unit', $attribut) ? null : (function ($unit, $amount, $locale) { diff --git a/src/MetricAmount.php b/src/MetricAmount.php index c4709e7..69f0ea6 100644 --- a/src/MetricAmount.php +++ b/src/MetricAmount.php @@ -24,7 +24,7 @@ private function compile(string $value, int $decimalRound = 4): string PATTERN; } - private function evaluate(array $context, array $value, int $decimalRound): float|null + private function evaluate(array $context, array $value, int $decimalRound): ?float { return !\is_array($value) || !\array_key_exists('amount', $value) ? null : round((float) $value['amount'], $decimalRound); } diff --git a/src/MetricUnit.php b/src/MetricUnit.php index d0986f6..49f1dfd 100644 --- a/src/MetricUnit.php +++ b/src/MetricUnit.php @@ -24,7 +24,7 @@ private function compile(string $value): string PATTERN; } - private function evaluate(array $context, array $value): string|null + private function evaluate(array $context, array $value): ?string { return !\is_array($value) || !\array_key_exists('unit', $value) ? null : $value['unit']; } diff --git a/src/WithMultipleOption.php b/src/WithMultipleOption.php index f2e5cdd..07b68d3 100644 --- a/src/WithMultipleOption.php +++ b/src/WithMultipleOption.php @@ -48,7 +48,7 @@ function (string \$code) use(\$input) { /** * @return array> */ - private function evaluate(array $context, array $codes, string $attribute, array $labels, string|null $locale = null, string|null $scope = null): array + private function evaluate(array $context, array $codes, string $attribute, array $labels, ?string $locale = null, ?string $scope = null): array { return [[ 'locale' => $locale, diff --git a/src/WithProductValueMediaFile.php b/src/WithProductValueMediaFile.php index fedec2f..e99ef79 100644 --- a/src/WithProductValueMediaFile.php +++ b/src/WithProductValueMediaFile.php @@ -30,7 +30,7 @@ private function compile(string $code, string $attribute, string $locale = 'null } /** - * @return array + * @return array */ private function evaluate(array $context, string $code, string $attribute, string $locale = 'null', string $scope = 'null'): array { diff --git a/src/WithReferenceEntitySimpleOption.php b/src/WithReferenceEntitySimpleOption.php index 6c34a1a..62cb37a 100644 --- a/src/WithReferenceEntitySimpleOption.php +++ b/src/WithReferenceEntitySimpleOption.php @@ -32,7 +32,7 @@ private function compile(string $code, string $locale = 'null', string $channel PHP; } - private function evaluate(array $context, string $code, string|null $locale = null, string|null $channel = null): array + private function evaluate(array $context, string $code, ?string $locale = null, ?string $channel = null): array { return [[ 'locale' => $locale, diff --git a/src/WithReferenceEntityValue.php b/src/WithReferenceEntityValue.php index ef56e6c..86f1f7c 100644 --- a/src/WithReferenceEntityValue.php +++ b/src/WithReferenceEntityValue.php @@ -22,7 +22,7 @@ private function compile(string $value, string $locale = 'null', string $channel return sprintf('([["data" => (%s), "locale" => (%s), "channel" => (%s)]])', $value, $locale, $channel); } - private function evaluate(array $context, string $value, string|null $locale = null, string|null $channel = null): array + private function evaluate(array $context, string $value, ?string $locale = null, ?string $channel = null): array { return [[ 'locale' => $locale, From 2d129e05b55b2dc51cebe553065a2943d18c066c Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 18 Jun 2024 15:21:24 +0200 Subject: [PATCH 5/5] fix default values on evaluate method --- src/WithProductValueMediaFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WithProductValueMediaFile.php b/src/WithProductValueMediaFile.php index e99ef79..69c9724 100644 --- a/src/WithProductValueMediaFile.php +++ b/src/WithProductValueMediaFile.php @@ -32,7 +32,7 @@ private function compile(string $code, string $attribute, string $locale = 'null /** * @return array */ - private function evaluate(array $context, string $code, string $attribute, string $locale = 'null', string $scope = 'null'): array + private function evaluate(array $context, string $code, string $attribute, ?string $locale = null, ?string $scope = null): array { return [ 'identifier' => $code,