Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomulik committed Nov 20, 2023
1 parent e063f1d commit a8355d7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Util/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use function is_array;
use function is_scalar;
use SebastianBergmann\RecursionContext\Context;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
Expand All @@ -26,7 +27,7 @@ public static function export(mixed $value, bool $exportObjects = false): string
return '{enable export of objects to see this value}';
}

private static function isScalarOrArrayOfScalars(mixed $value): bool
private static function isScalarOrArrayOfScalars(mixed &$value, Context $context = null): bool
{
if (is_scalar($value)) {
return true;
Expand All @@ -36,8 +37,19 @@ private static function isScalarOrArrayOfScalars(mixed $value): bool
return false;
}

foreach ($value as $_value) {
if (!self::isScalarOrArrayOfScalars($_value)) {
if (!$context) {
$context = new Context;
}

if ($context->contains($value) !== false) {
return true;
}

$array = $value;
$context->add($value);

foreach ($array as &$_value) {
if (!self::isScalarOrArrayOfScalars($_value, $context)) {
return false;
}
}
Expand Down

0 comments on commit a8355d7

Please sign in to comment.