Skip to content

Commit e8dcb0e

Browse files
committed
refactor code
1 parent f856114 commit e8dcb0e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

helpers/presento.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,21 @@ function get_from_array(array $map, string $node)
4848
return null;
4949
}
5050

51+
}
52+
53+
if (!function_exists('is_collection')) {
54+
/**
55+
* Check given value is multidimensional array
56+
*
57+
* @param array $arr
58+
* @return bool
59+
*/
60+
function is_collection(array $arr) : bool
61+
{
62+
if (!is_array($arr)) {
63+
return false;
64+
}
65+
66+
return isset($arr[0]) && is_array($arr[0]);
67+
}
5168
}

src/Presenter.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function transformer()
4343
*/
4444
public function handle() : array
4545
{
46-
if ($this->isCollection($this->data)) {
46+
if (is_collection($this->data)) {
4747
$generatedData = [];
4848
foreach ($this->data as $property => $data) {
4949
$generatedData[$property] = $this->transform($this->process($data));
@@ -124,19 +124,4 @@ public function get() : array
124124
{
125125
return $this->generatedData;
126126
}
127-
128-
/**
129-
* Check given value is multidimensional array
130-
*
131-
* @param array $arr
132-
* @return bool
133-
*/
134-
protected function isCollection(array $arr) : bool
135-
{
136-
if (!is_array($arr)) {
137-
return false;
138-
}
139-
140-
return isset($arr[0]) && is_array($arr[0]);
141-
}
142127
}

0 commit comments

Comments
 (0)