Skip to content

Commit 696cabc

Browse files
committed
Stan fixes
1 parent 787b040 commit 696cabc

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

src/Processors/DataProcessor.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function process($object = false): array
8181
* Process add columns.
8282
*
8383
* @param array $data
84-
* @param mixed $row
84+
* @param array|object $row
8585
* @return array
8686
*
8787
* @throws \Exception
@@ -108,15 +108,15 @@ protected function addColumns(array $data, $row): array
108108
/**
109109
* Process edit columns.
110110
*
111-
* @param mixed $data
112-
* @param mixed $row
111+
* @param array $data
112+
* @param array|object $row
113113
* @return array
114114
*
115115
* @throws \Exception
116116
*/
117-
protected function editColumns($data, $row): array
117+
protected function editColumns(array $data, object|array $row): array
118118
{
119-
foreach ($this->editColumns as $key => $value) {
119+
foreach ($this->editColumns as $value) {
120120
$value['content'] = Helper::compileContent($value['content'], $data, $row);
121121
Arr::set($data, $value['name'], $value['content']);
122122
}
@@ -128,12 +128,12 @@ protected function editColumns($data, $row): array
128128
* Setup additional DT row variables.
129129
*
130130
* @param array $data
131-
* @param mixed $row
131+
* @param array|object $row
132132
* @return array
133133
*
134134
* @throws \Exception
135135
*/
136-
protected function setupRowVariables($data, $row): array
136+
protected function setupRowVariables(array $data, object|array $row): array
137137
{
138138
$processor = new RowProcessor($data, $row);
139139

src/Processors/RowProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class RowProcessor
99
{
1010
/**
1111
* @param array $data
12-
* @param mixed $row
12+
* @param array|object $row
1313
*/
14-
public function __construct(protected $data, protected $row)
14+
public function __construct(protected array $data, protected $row)
1515
{
1616
}
1717

src/Utilities/Helper.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use Illuminate\Contracts\Support\Arrayable;
77
use Illuminate\Support\Arr;
88
use Illuminate\Support\Str;
9-
use stdClass;
10-
use Yajra\DataTables\Exceptions\Exception;
119

1210
class Helper
1311
{
@@ -58,12 +56,12 @@ protected static function isItemOrderInvalid($item, $array)
5856
*
5957
* @param mixed $content Pre-processed content
6058
* @param array $data data to use with blade template
61-
* @param mixed $param parameter to call with callable
59+
* @param array|object $param parameter to call with callable
6260
* @return mixed
6361
*
6462
* @throws \Exception
6563
*/
66-
public static function compileContent($content, array $data, $param)
64+
public static function compileContent($content, array $data, array|object $param)
6765
{
6866
if (is_string($content)) {
6967
return static::compileBlade($content, static::getMixedValue($data, $param));
@@ -102,10 +100,10 @@ public static function compileBlade($str, $data = [])
102100
* Get a mixed value of custom data and the parameters.
103101
*
104102
* @param array $data
105-
* @param mixed $param
103+
* @param array|object $param
106104
* @return array
107105
*/
108-
public static function getMixedValue(array $data, $param)
106+
public static function getMixedValue(array $data, array|object $param)
109107
{
110108
$casted = self::castToArray($param);
111109

@@ -123,26 +121,16 @@ public static function getMixedValue(array $data, $param)
123121
/**
124122
* Cast the parameter into an array.
125123
*
126-
* @param mixed $param
124+
* @param array|object $param
127125
* @return array
128-
*
129-
* @throws \Yajra\DataTables\Exceptions\Exception
130126
*/
131-
public static function castToArray($param): array
127+
public static function castToArray(array|object $param): array
132128
{
133-
if (is_array($param)) {
134-
return $param;
135-
}
136-
137-
if ($param instanceof stdClass) {
138-
return (array) $param;
139-
}
140-
141129
if ($param instanceof Arrayable) {
142130
return $param->toArray();
143131
}
144132

145-
throw new Exception('Invalid parameter type.');
133+
return (array) $param;
146134
}
147135

148136
/**
@@ -169,8 +157,10 @@ public static function getOrMethod($method)
169157
*/
170158
public static function convertToArray($row, $filters = [])
171159
{
172-
$row = is_object($row) && method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden', [])) : $row;
173-
$row = is_object($row) && method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible', [])) : $row;
160+
$row = is_object($row) && method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden',
161+
[])) : $row;
162+
$row = is_object($row) && method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible',
163+
[])) : $row;
174164
$data = $row instanceof Arrayable ? $row->toArray() : (array) $row;
175165

176166
foreach ($data as &$value) {

0 commit comments

Comments
 (0)