diff --git a/src/Build.php b/src/Build.php index 503fc3e..e4f39c7 100644 --- a/src/Build.php +++ b/src/Build.php @@ -12,17 +12,17 @@ public function __construct($name) { parent::__construct( $name, - \Closure::fromCallable([$this, 'compile'])->bindTo($this), - \Closure::fromCallable([$this, 'evaluate'])->bindTo($this) + $this->compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) ); } - private function compile(string $input, string ...$values) + private function compile(string ...$values): string { return sprintf('array_values(array_merge(%s))', implode(', ', $values)); } - private function evaluate(array $context, array ...$values) + private function evaluate(array $context, array ...$values): array { return array_values(array_merge(...$values)); } diff --git a/src/Value.php b/src/Value.php index d63f47f..6ff9305 100644 --- a/src/Value.php +++ b/src/Value.php @@ -1,40 +1,43 @@ -scope = $scope; - + return $this; } - + public function withoutScope(): self { $this->scope = null; - + return $this; } - + public function withLocale(string $locale): self { $this->locale = $locale; - + return $this; } - + public function withoutLocale(): self { $this->locale = null; - + return $this; } diff --git a/src/WithMultipleOption.php b/src/WithMultipleOption.php index 67c849a..65fe654 100644 --- a/src/WithMultipleOption.php +++ b/src/WithMultipleOption.php @@ -12,32 +12,32 @@ public function __construct($name) { parent::__construct( $name, - \Closure::fromCallable([$this, 'compile'])->bindTo($this), - \Closure::fromCallable([$this, 'evaluate'])->bindTo($this) + $this->compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) ); } - private function compile(string $codes, string $attribute, string $labels, string $locale, string $scope) + private function compile(string $codes, string $attribute, string $labels, string $locale, string $scope): string { return << $attribute, + 'attribute' => {$attribute}, 'code' => \$code, 'labels' => \$labels[\$code] ?? [], ]; }, - $codes, + {$codes}, ); return [ [ - 'data' => ($codes), - 'locale' => $locale, - 'scope' => $scope, + 'data' => ({$codes}), + 'locale' => {$locale}, + 'scope' => {$scope}, 'linked_data' => \$linkedData, ], ]; @@ -46,23 +46,20 @@ function (string \$code) { } /** - * @var list $codes - * @var array> $labels + * @return array> */ - private function evaluate(array $context, array $codes, string $attribute, array $labels, ?string $locale = null, ?string $scope = null) + private function evaluate(array $context, array $codes, string $attribute, array $labels, ?string $locale = null, ?string $scope = null): array { return [[ 'locale' => $locale, 'scope' => $scope, 'data' => $codes, 'linked_data' => array_map( - function (string $code) use ($attribute, $labels) { - return [ - 'attribute' => $attribute, - 'code' => $code, - 'labels' => $labels[$code] ?? [], - ]; - }, + fn (string $code) => [ + 'attribute' => $attribute, + 'code' => $code, + 'labels' => $labels[$code] ?? [], + ], $codes ), ]]; diff --git a/src/WithSimpleOption.php b/src/WithSimpleOption.php index f8f29e4..35b37b0 100644 --- a/src/WithSimpleOption.php +++ b/src/WithSimpleOption.php @@ -12,23 +12,23 @@ public function __construct($name) { parent::__construct( $name, - \Closure::fromCallable([$this, 'compile'])->bindTo($this), - \Closure::fromCallable([$this, 'evaluate'])->bindTo($this) + $this->compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) ); } - private function compile(string $code, string $attribute, string $labels, string $locale = 'null', string $scope = 'null') + private function compile(string $code, string $attribute, string $labels, string $locale = 'null', string $scope = 'null'): string { return << ($code), - 'locale' => $locale, - 'scope' => $scope, + 'data' => ({$code}), + 'locale' => {$locale}, + 'scope' => {$scope}, 'linked_data' => [ - 'attribute' => ($attribute), - 'code' => ($code), - 'labels' => ($labels), + 'attribute' => ({$attribute}), + 'code' => ({$code}), + 'labels' => ({$labels}), ], ], ]) @@ -36,9 +36,9 @@ private function compile(string $code, string $attribute, string $labels, string } /** - * @var array $labels + * @return array|string|null>> */ - private function evaluate(array $context, string $code, string $attribute, array $labels, ?string $locale = null, ?string $scope = null) + 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 f030f51..0f34b39 100644 --- a/src/WithValue.php +++ b/src/WithValue.php @@ -12,17 +12,17 @@ public function __construct($name) { parent::__construct( $name, - \Closure::fromCallable([$this, 'compile'])->bindTo($this), - \Closure::fromCallable([$this, 'evaluate'])->bindTo($this) + $this->compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) ); } - private function compile(string $value, string $locale = 'null', string $scope = 'null') + private function compile(string $value, string $locale = 'null', string $scope = 'null'): string { return sprintf('([["data" => (%s), "locale" => (%s), "scope" => (%s)]])', $value, $locale, $scope); } - private function evaluate(array $context, string $value, ?string $locale = null, ?string $scope = null) + private function evaluate(array $context, string $value, ?string $locale = null, ?string $scope = null): array { return [[ 'locale' => $locale,