Skip to content

Commit

Permalink
fix issue #5567
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomulik committed Nov 19, 2023
1 parent e57e12a commit e2af5ee
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;

Check warning on line 45 in src/Util/Exporter.php

View check run for this annotation

Codecov / codecov/patch

src/Util/Exporter.php#L45

Added line #L45 was not covered by tests
}

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

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

0 comments on commit e2af5ee

Please sign in to comment.