Skip to content

Commit

Permalink
Fixed return type variable (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis authored Mar 18, 2023
1 parent 068d2b7 commit a4001fc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,26 @@ public static function esc(string $string): string
}

/**
* Returns JSON object from array.
* Returns Data object from array.
*/
public static function data(Data|array $data): Data
{
if ($data instanceof Data) {
return $data;
}

return new Data($data);
}

/**
* Returns JSON object from array.
*/
public static function json(JSON|array $data): JSON
{
if ($data instanceof JSON) {
return $data;
}

return new JSON($data);
}

Expand Down
16 changes: 15 additions & 1 deletion tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace JBZoo\PHPUnit;

use JBZoo\Data\Data;
use JBZoo\Data\JSON;
use JBZoo\Utils\Filter;

Expand Down Expand Up @@ -342,10 +343,23 @@ public function testData(): void
'key' => 'value',
];

$obj = new JSON($data);
$obj = new Data($data);

isSame($obj, Filter::data($obj));
isSame($data, (array)Filter::data($obj));
isSame($data, (array)Filter::data($data));
}

public function testJson(): void
{
$data = [
'key' => 'value',
];

$obj = new JSON($data);

isSame($obj, Filter::json($obj));
isSame($data, (array)Filter::json($obj));
isSame($data, (array)Filter::json($data));
}
}

0 comments on commit a4001fc

Please sign in to comment.