Skip to content

Commit

Permalink
Fix wrong dimensions when the first element is false.
Browse files Browse the repository at this point in the history
  • Loading branch information
yutmr committed Jan 6, 2017
1 parent 9eb07d5 commit 072d8cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utility/Hash.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public static function dimensions(array $data)
public static function maxDimensions(array $data) public static function maxDimensions(array $data)
{ {
$depth = []; $depth = [];
if (is_array($data) && reset($data) !== false) { if (is_array($data) && !empty($data)) {
foreach ($data as $value) { foreach ($data as $value) {
if (is_array($value)) { if (is_array($value)) {
$depth[] = static::maxDimensions($value) + 1; $depth[] = static::maxDimensions($value) + 1;
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase/Utility/HashTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ public function testMaxDimensions()
]; ];
$result = Hash::maxDimensions($data); $result = Hash::maxDimensions($data);
$this->assertEquals($result, 5); $this->assertEquals($result, 5);

$data = [
'1' => false,
'2' => ['2.1' => '2.1.1']
];
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 2);
} }


/** /**
Expand Down

0 comments on commit 072d8cf

Please sign in to comment.