Skip to content

Commit

Permalink
Port Hash::maxDimension() fixes to 3.0
Browse files Browse the repository at this point in the history
Port fixes from #7040 and #7041 to 3.0.
  • Loading branch information
markstory committed Jul 21, 2015
1 parent 05fa5e3 commit 742f85d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Utility/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ public static function maxDimensions(array $data)
if (is_array($data) && reset($data) !== false) {
foreach ($data as $value) {
if (is_array($value)) {
$depth[] = static::dimensions($value) + 1;
$depth[] = static::maxDimensions($value) + 1;
} else {
$depth[] = 1;
}
Expand Down
29 changes: 10 additions & 19 deletions tests/TestCase/Utility/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,25 +310,16 @@ public function testMaxDimensions()
$this->assertEquals($result, 4);

$data = [
'1' => ['1.1' => '1.1.1'],
['2' => ['2.1' => ['2.1.1' => ['2.1.1.1']]]],
'3' => ['3.1' => ['3.1.1' => '3.1.1.1']]
];
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 5);

$data = [
'1' => ['1.1' => '1.1.1'],
['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]],
'3' => ['3.1' => ['3.1.1' => '3.1.1.1']]
];
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 5);

$data = [
'1' => ['1.1' => '1.1.1'],
['2' => ['2.1' => ['2.1.1' => ['2.1.1.1' => '2.1.1.1.1']]]],
'3' => ['3.1' => ['3.1.1' => '3.1.1.1']]
'1' => [
'1.1' => '1.1.1',
'1.2' => [
'1.2.1' => [
'1.2.1.1',
['1.2.2.1']
]
]
],
'2' => ['2.1' => '2.1.1',]
];
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 5);
Expand Down

0 comments on commit 742f85d

Please sign in to comment.