Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and sebastianbergmann committed Jun 18, 2024
1 parent f5ba9b0 commit 085f691
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public function shortenedRecursiveExport(array &$data, ?RecursionContext $proces
$overallCount = count($data, COUNT_RECURSIVE);
$counter = 0;

$export = $this->shortenedCountedRecursiveExport($data, $processed, $overallCount, $counter);
$export = $this->shortenedCountedRecursiveExport($data, $processed, $counter);

if ($overallCount > $this->shortenArraysLongerThan) {
$export .= sprintf(' ...%d more elements', $overallCount - $this->shortenArraysLongerThan);
$export .= sprintf(', ...%d more elements', $overallCount - $this->shortenArraysLongerThan);
}

return $export;
Expand Down Expand Up @@ -189,7 +189,7 @@ public function toArray(mixed $value): array
return $array;
}

private function shortenedCountedRecursiveExport(array &$data, RecursionContext $processed, int $overallCount, int &$counter): string
private function shortenedCountedRecursiveExport(array &$data, RecursionContext $processed, int &$counter): string
{
$result = [];

Expand All @@ -199,15 +199,15 @@ private function shortenedCountedRecursiveExport(array &$data, RecursionContext
$processed->add($data);

foreach ($array as $key => $value) {
if ($overallCount > $this->shortenArraysLongerThan && $counter > $this->shortenArraysLongerThan) {
if ($counter > $this->shortenArraysLongerThan) {
break;
}

if (is_array($value)) {
if ($processed->contains($data[$key]) !== false) {
$result[] = '*RECURSION*';
} else {
$result[] = '[' . $this->shortenedCountedRecursiveExport($data[$key], $processed, $overallCount, $counter) . ']';
$result[] = '[' . $this->shortenedCountedRecursiveExport($data[$key], $processed, $counter) . ']';
}
} else {
$result[] = $this->shortenedExport($value);
Expand Down
4 changes: 2 additions & 2 deletions tests/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ public static function shortenedRecursiveExportProvider(): array
'with assoc array key' => [['foo' => 'bar'], '\'bar\''],
'multidimensional array' => [[[1, 2, 3], [3, 4, 5]], '[1, 2, 3], [3, 4, 5]'],
'object' => [[new stdClass], 'stdClass Object ()'],
'big array' => [$bigArray, "'cast('foo0' as blob)', 'cast('foo1' as blob)', 'cast('foo2' as blob)', 'cast('foo3' as blob)', 'cast('foo4' as blob)', 'cast('foo5' as blob)', 'cast('foo6' as blob)', 'cast('foo7' as blob)', 'cast('foo8' as blob)', 'cast('foo9' as blob)', 'cast('foo10' as blob)' ...19990 more elements"],
'deep array' => [$deepArray, "[1, 2, 'hello', 'world', true, false], [[1, 2, 'hello', 'world']] ...69 more elements"],
'big array' => [$bigArray, "'cast('foo0' as blob)', 'cast('foo1' as blob)', 'cast('foo2' as blob)', 'cast('foo3' as blob)', 'cast('foo4' as blob)', 'cast('foo5' as blob)', 'cast('foo6' as blob)', 'cast('foo7' as blob)', 'cast('foo8' as blob)', 'cast('foo9' as blob)', 'cast('foo10' as blob)', ...19990 more elements"],
'deep array' => [$deepArray, "[1, 2, 'hello', 'world', true, false], [[1, 2, 'hello', 'world']], ...69 more elements"],
];
}

Expand Down

0 comments on commit 085f691

Please sign in to comment.