Skip to content

Commit

Permalink
deps
Browse files Browse the repository at this point in the history
  • Loading branch information
surgiie committed May 27, 2024
1 parent 448a1f6 commit 692ac2d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/UsesTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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,
Expand All @@ -224,8 +224,8 @@ protected function prepareArguments($value, $function, array $args = [])
};
}


}

return $parameters;
}

Expand Down
2 changes: 1 addition & 1 deletion src/TransformerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 3 additions & 4 deletions tests/Unit/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ function ($value) {
class Example
{
protected $value;

public function __construct($value)
{
$this->value = $value;
}

public function concat($string)
{
return $this->value . $string;
return $this->value.$string;
}

}

function example($value)
Expand All @@ -92,7 +92,6 @@ function example($value)
expect($formatter->transform())->toBe('foobar');
});


it('can cast arguments', function () {

function example_two(int $value)
Expand All @@ -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);
Expand Down

0 comments on commit 692ac2d

Please sign in to comment.