diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f893ba7..a9804d9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,14 +16,14 @@ jobs: if: ${{ github.actor != 'github-actions[bot]' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Validate composer.json and composer.lock run: composer validate --strict - name: Cache Composer packages id: composer-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: vendor key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} diff --git a/composer.json b/composer.json index db1e35c..84c97e7 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0.2", + "php": "^8.2.0", "illuminate/http": "^9.0|^10.0|^11.0", "illuminate/support": "^9.0|^10.0|^11.0", "illuminate/validation": "^9.0|^10.0|^11.0" diff --git a/src/Concerns/UsesTransformer.php b/src/Concerns/UsesTransformer.php index 2f88089..727f342 100644 --- a/src/Concerns/UsesTransformer.php +++ b/src/Concerns/UsesTransformer.php @@ -8,7 +8,7 @@ trait UsesTransformer { /**Return a new Transformer instance.*/ - public function transformer($value = '', array $transformers = [], string|null $name = null): Transformer + public function transformer($value = '', array $transformers = [], ?string $name = null): Transformer { return new Transformer($value, $transformers, $name); } @@ -20,7 +20,7 @@ public function dataTransformer(array $data = [], array $functions = []): DataTr } /**Transform the given value.*/ - public function transform($value = '', array $functions = [], string|null $name = null) + public function transform($value = '', array $functions = [], ?string $name = null) { return $this->transformer($value, $functions, $name)->transform(); } diff --git a/src/Transformer.php b/src/Transformer.php index e12e2a4..3408db0 100644 --- a/src/Transformer.php +++ b/src/Transformer.php @@ -31,7 +31,7 @@ class Transformer /** * Construct a new Transformer instance. */ - public function __construct($value = '', array|string $functions = [], string $name = null) + public function __construct($value = '', array|string $functions = [], ?string $name = null) { $this->setValue($value); $this->setName($name); @@ -65,7 +65,7 @@ protected function call($method, $value, array $args = []) //check if its a custom transformable class if ($function instanceof Transformable) { return $function->transform($value, $this->abortTransformationCallback()); - // or a callback + // or a callback } elseif ($function instanceof Closure) { return $function($value, $this->abortTransformationCallback()); } @@ -82,7 +82,7 @@ protected function call($method, $value, array $args = []) } /**Set the name of the value/input being transformed.*/ - protected function setName(null|string $name = null): static + protected function setName(?string $name = null): static { $this->name = $name; @@ -201,7 +201,7 @@ protected function prepareArguments($value, $function, array $args = []) $parameters = array_merge($defaults, $args); foreach ($parameters as $index => $param) { - if(!is_string($param)){ + if (! is_string($param)) { continue; } @@ -211,10 +211,10 @@ protected function prepareArguments($value, $function, array $args = []) break; } // allow params to be to be casted to a specific type - if(preg_match('/.+@(int|str|float|bool|array|object)/', $param, $matches)){ + if (preg_match('/.+@(int|str|float|bool|array|object)/', $param, $matches)) { $type = $matches[1]; $param = rtrim($param, "@$type"); - $parameters[$index] = match($type){ + $parameters[$index] = match ($type) { 'int' => (int) $param, 'str' => (string) $param, 'float' => (float) $param, @@ -224,8 +224,8 @@ protected function prepareArguments($value, $function, array $args = []) }; } - } + return $parameters; } diff --git a/src/TransformerServiceProvider.php b/src/TransformerServiceProvider.php index 262e7c8..214f29e 100644 --- a/src/TransformerServiceProvider.php +++ b/src/TransformerServiceProvider.php @@ -9,7 +9,7 @@ class TransformerServiceProvider extends ServiceProvider { public function boot() { - Request::macro('transform', function (array $input, array $transformers = null): array { + Request::macro('transform', function (array $input, ?array $transformers = null): array { $localTransformers = $transformers ?? $input; $input = is_null($transformers) ? (method_exists($this, 'validated') diff --git a/tests/Unit/TransformerTest.php b/tests/Unit/TransformerTest.php index 600af33..ea0aa9e 100644 --- a/tests/Unit/TransformerTest.php +++ b/tests/Unit/TransformerTest.php @@ -66,6 +66,7 @@ function ($value) { class Example { protected $value; + public function __construct($value) { $this->value = $value; @@ -73,9 +74,8 @@ public function __construct($value) public function concat($string) { - return $this->value . $string; + return $this->value.$string; } - } function example($value) @@ -92,7 +92,6 @@ function example($value) expect($formatter->transform())->toBe('foobar'); }); - it('can cast arguments', function () { function example_two(int $value) @@ -102,7 +101,7 @@ function example_two(int $value) $formatter = (new Transformer(1, [ 'trim', - 'example_two:1@int' + 'example_two:1@int', ])); expect($formatter->transform())->toBe(2);