Skip to content

Commit

Permalink
Added array and object castable
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Jan 28, 2020
1 parent 31c18f1 commit 641c32b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Concerns/HasCastable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Helldar\PrettyArray\Concerns;

use function addslashes;
use function is_array;
use function is_bool;
use function is_numeric;
use function is_null;
use function is_numeric;
use function is_object;

trait HasCastable
{
Expand All @@ -30,6 +32,10 @@ protected function castValue($value = null)
return 'null';
}

if (is_array($value) || is_object($value)) {
return '[]';
}

return "'" . addslashes($value) . "'";
}
}
2 changes: 1 addition & 1 deletion src/Services/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function pad(string $value, int $pad = 1, $type = STR_PAD_LEFT): strin

protected function value($value, int $pad = 1)
{
if (is_array($value)) {
if (! empty($value) && (is_array($value) || is_object($value))) {
return $this->raw($value, $pad);
}

Expand Down

0 comments on commit 641c32b

Please sign in to comment.