Skip to content

Commit

Permalink
Change parameter name to $fail
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Nov 9, 2024
1 parent 5f23423 commit 7898b5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public static function handler(string $type): Handler
public static function decode(
$string,
string $type,
bool $exceptions = true
bool $fail = true
): array {
try {
return static::handler($type)->decode($string);
} catch (Throwable $e) {
if ($exceptions === false) {
if ($fail === false) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Field/LayoutField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(array $params)

public function fill(mixed $value = null): void
{
$value = Data::decode($value, type: 'json', exceptions: false);
$value = Data::decode($value, type: 'json', fail: false);
$layouts = Layouts::factory($value, ['parent' => $this->model])->toArray();

foreach ($layouts as $layoutIndex => $layout) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Data/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public function testDecodeInvalid3($handler)
Data::decode(true, $handler);
}

/**
* @covers ::decode
* @dataProvider handlerProvider
*/
public function testDecodeInvalidNoExceptions($handler)
{
$data = Data::decode(1, $handler, fail: false);
$this->assertSame([], $data);
}

public static function handlerProvider(): array
{
// the PHP handler doesn't support decoding and therefore cannot be
Expand Down

0 comments on commit 7898b5d

Please sign in to comment.