diff --git a/.github/workflows/phpstan-5.yaml b/.github/workflows/phpstan-5.yaml index 906b4c9..f6dd9bf 100644 --- a/.github/workflows/phpstan-5.yaml +++ b/.github/workflows/phpstan-5.yaml @@ -1,7 +1,7 @@ name: PHPStan level 5 on: push jobs: - phpstan: + phpstan5: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-6.yaml b/.github/workflows/phpstan-6.yaml index a367107..a0faf6b 100644 --- a/.github/workflows/phpstan-6.yaml +++ b/.github/workflows/phpstan-6.yaml @@ -1,7 +1,7 @@ name: PHPStan level 6 on: push jobs: - phpstan: + phpstan6: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-7.yaml b/.github/workflows/phpstan-7.yaml index cad733d..c0a6ec6 100644 --- a/.github/workflows/phpstan-7.yaml +++ b/.github/workflows/phpstan-7.yaml @@ -1,7 +1,7 @@ name: PHPStan level 7 on: push jobs: - phpstan: + phpstan7: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-8.yaml b/.github/workflows/phpstan-8.yaml index 8d7aec6..4fa22f1 100644 --- a/.github/workflows/phpstan-8.yaml +++ b/.github/workflows/phpstan-8.yaml @@ -1,7 +1,7 @@ name: PHPStan level 8 on: push jobs: - phpstan: + phpstan8: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/src/AkeneoBuilderProvider.php b/src/AkeneoBuilderProvider.php index d64105d..a6f2905 100644 --- a/src/AkeneoBuilderProvider.php +++ b/src/AkeneoBuilderProvider.php @@ -13,6 +13,8 @@ public function getFunctions(): array return [ new Build('build'), new WithValue('withValue'), + new WithReferenceEntityValue('withReferenceEntityValue'), + new WithReferenceEntitySimpleOption('withReferenceEntitySimpleOption'), new WithSimpleOption('withSimpleOption'), new WithMultipleOption('withMultipleOption'), ]; diff --git a/src/DateTime.php b/src/DateTime.php index be90f60..67220c9 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -17,7 +17,7 @@ public function __construct($name) ); } - private function compile(string $date, ?string $format = null): string + private function compile(string $date, string|null $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 $format = null): string return sprintf('\DateTimeImmutable::createFromFormat(%s, %s, new \DateTimeZone("UTC"))', $date, $format); } - private function evaluate(array $context, string $date, ?string $format = null): \DateTimeInterface + private function evaluate(array $context, string $date, string|null $format = null): \DateTimeInterface { if (null === $format) { return new \DateTimeImmutable($date, new \DateTimeZone('UTC')); diff --git a/src/DateTimeZone.php b/src/DateTimeZone.php index 6cf0335..9d0392c 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 $format = null): string + private function compile(string $date, string $zone, string|null $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 $format = null): st return sprintf('\DateTimeImmutable::createFromFormat(%s, %s, new \DateTimeZone(%s))', $date, $format, $zone); } - private function evaluate(array $context, string $date, string $zone, ?string $format = null): \DateTimeInterface + private function evaluate(array $context, string $date, string $zone, string|null $format = null): \DateTimeInterface { if (null === $format) { return new \DateTimeImmutable($date, new \DateTimeZone($zone)); diff --git a/src/WithMultipleOption.php b/src/WithMultipleOption.php index 65fe654..8466408 100644 --- a/src/WithMultipleOption.php +++ b/src/WithMultipleOption.php @@ -17,12 +17,12 @@ public function __construct($name) ); } - private function compile(string $codes, string $attribute, string $labels, string $locale, string $scope): string + private function compile(string $codes, string $attribute, string $labels, string $locale = 'null', string $scope = 'null'): string { return << \$linkedData, ], ]; - )() + })() PHP; } /** * @return array> */ - private function evaluate(array $context, array $codes, string $attribute, array $labels, ?string $locale = null, ?string $scope = null): array + private function evaluate(array $context, array $codes, string $attribute, array $labels, string|null $locale = null, string|null $scope = null): array { return [[ 'locale' => $locale, diff --git a/src/WithReferenceEntitySimpleOption.php b/src/WithReferenceEntitySimpleOption.php new file mode 100644 index 0000000..6c34a1a --- /dev/null +++ b/src/WithReferenceEntitySimpleOption.php @@ -0,0 +1,45 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $code, string $locale = 'null', string $channel = 'null'): string + { + return << [ + {$code} + ], + 'locale' => {$locale}, + 'channel' => {$channel}, + ], + ]) + PHP; + } + + private function evaluate(array $context, string $code, string|null $locale = null, string|null $channel = null): array + { + return [[ + 'locale' => $locale, + 'channel' => $channel, + 'data' => [ + $code, + ], + ]]; + } +} diff --git a/src/WithReferenceEntityValue.php b/src/WithReferenceEntityValue.php new file mode 100644 index 0000000..ef56e6c --- /dev/null +++ b/src/WithReferenceEntityValue.php @@ -0,0 +1,33 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $value, string $locale = 'null', string $channel = 'null'): string + { + 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 + { + return [[ + 'locale' => $locale, + 'channel' => $channel, + 'data' => $value, + ]]; + } +} diff --git a/src/WithSimpleOption.php b/src/WithSimpleOption.php index 35b37b0..9ee9a67 100644 --- a/src/WithSimpleOption.php +++ b/src/WithSimpleOption.php @@ -38,7 +38,7 @@ private function compile(string $code, string $attribute, string $labels, string /** * @return array|string|null>> */ - private function evaluate(array $context, string $code, string $attribute, array $labels, ?string $locale = null, ?string $scope = null): array + private function evaluate(array $context, string $code, string $attribute, array $labels, string $locale = 'null', string $scope = 'null'): array { return [[ 'locale' => $locale, diff --git a/src/WithValue.php b/src/WithValue.php index 0f34b39..d30457e 100644 --- a/src/WithValue.php +++ b/src/WithValue.php @@ -22,7 +22,7 @@ private function compile(string $value, string $locale = 'null', string $scope = return sprintf('([["data" => (%s), "locale" => (%s), "scope" => (%s)]])', $value, $locale, $scope); } - private function evaluate(array $context, string $value, ?string $locale = null, ?string $scope = null): array + private function evaluate(array $context, string $value, string $locale = 'null', string $scope = 'null'): array { return [[ 'locale' => $locale,