Skip to content

Commit 429728e

Browse files
committed
Fix @phpstan-ignore-next-line
1 parent c3b9896 commit 429728e

File tree

6 files changed

+76
-19
lines changed

6 files changed

+76
-19
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
},
2424
"require-dev": {
2525
"nunomaduro/larastan": "^2.1",
26-
"orchestra/testbench": "^7.3"
26+
"orchestra/testbench": "^7.3",
27+
"yajra/laravel-datatables-html": "^9.0"
2728
},
2829
"suggest": {
2930
"yajra/laravel-datatables-buttons": "Plugin for server-side exporting of dataTables.",

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ parameters:
99
level: max
1010

1111
ignoreErrors:
12+
- '#Unsafe usage of new static\(\).#'
1213

1314
excludePaths:
1415
- src/helper.php

src/Contracts/Formatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface Formatter
66
{
77
/**
88
* @param mixed $value
9-
* @param mixed $row
9+
* @param array|\Illuminate\Database\Eloquent\Model|object $row
1010
* @return string
1111
*/
1212
public function format($value, $row);

src/DataTableAbstract.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,10 @@ public static function canCreate($source)
167167
* Factory method, create and return an instance for the DataTable engine.
168168
*
169169
* @param mixed $source
170-
* @return $this
170+
* @return static
171171
*/
172172
public static function create($source)
173173
{
174-
/** @phpstan-ignore-next-line */
175174
return new static($source);
176175
}
177176

src/DataTables.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Contracts\Database\Query\Builder as QueryBuilder;
77
use Illuminate\Support\Traits\Macroable;
88
use Yajra\DataTables\Exceptions\Exception;
9+
use Yajra\DataTables\Html\Builder;
910

1011
class DataTables
1112
{
@@ -21,11 +22,9 @@ class DataTables
2122
/**
2223
* HTML builder instance.
2324
*
24-
* @phpstan-ignore-next-line
25-
*
2625
* @var \Yajra\DataTables\Html\Builder|null
2726
*/
28-
protected $html = null;
27+
protected ?Builder $html = null;
2928

3029
/**
3130
* Make a DataTable instance from source.
@@ -60,8 +59,10 @@ public static function make($source)
6059
$callback = [$engines[$engine], 'create'];
6160

6261
if (is_callable($callback)) {
63-
// @phpstan-ignore-next-line
64-
return call_user_func_array($callback, $args);
62+
/** @var \Yajra\DataTables\DataTableAbstract $instance */
63+
$instance = call_user_func_array($callback, $args);
64+
65+
return $instance;
6566
}
6667
}
6768
}
@@ -72,8 +73,10 @@ public static function make($source)
7273
$create = [$engine, 'create'];
7374

7475
if (is_callable($create)) {
75-
// @phpstan-ignore-next-line
76-
return call_user_func_array($create, $args);
76+
/** @var \Yajra\DataTables\DataTableAbstract $instance */
77+
$instance = call_user_func_array($create, $args);
78+
79+
return $instance;
7780
}
7881
}
7982
}
@@ -137,15 +140,13 @@ public function collection($collection): CollectionDataTable
137140
/**
138141
* Get html builder instance.
139142
*
140-
* @phpstan-ignore-next-line
141-
*
142143
* @return \Yajra\DataTables\Html\Builder
143144
*
144-
* @throws Exception
145+
* @throws \Yajra\DataTables\Exceptions\Exception
145146
*/
146147
public function getHtmlBuilder()
147148
{
148-
if (! class_exists('\Yajra\DataTables\Html\Builder')) {
149+
if (! class_exists(Builder::class)) {
149150
throw new Exception('Please install yajra/laravel-datatables-html to be able to use this function.');
150151
}
151152

src/Processors/DataProcessor.php

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,73 @@
99

1010
class DataProcessor
1111
{
12+
/**
13+
* @var int
14+
*/
1215
protected int $start;
16+
/**
17+
* @var array
18+
*/
1319
protected array $output = [];
20+
21+
/**
22+
* @var array<array-key, array{name: string, content: mixed}>
23+
*/
1424
protected array $appendColumns = [];
25+
26+
/**
27+
* @var array<array-key, array{name: string, content: mixed}>
28+
*/
1529
protected array $editColumns = [];
30+
31+
/**
32+
* @var array
33+
*/
1634
protected array $templates = [];
35+
36+
/**
37+
* @var array
38+
*/
1739
protected array $rawColumns = [];
40+
41+
/**
42+
* @var array|string[]
43+
*/
1844
protected array $exceptions = ['DT_RowId', 'DT_RowClass', 'DT_RowData', 'DT_RowAttr'];
45+
46+
/**
47+
* @var array
48+
*/
1949
protected array $onlyColumns = [];
50+
51+
/**
52+
* @var array
53+
*/
2054
protected array $makeHidden = [];
55+
56+
/**
57+
* @var array
58+
*/
2159
protected array $makeVisible = [];
60+
61+
/**
62+
* @var array
63+
*/
2264
protected array $excessColumns = [];
65+
66+
/**
67+
* @var string|array
68+
*/
2369
protected mixed $escapeColumns = [];
70+
71+
/**
72+
* @var iterable
73+
*/
2474
protected iterable $results;
75+
76+
/**
77+
* @var bool
78+
*/
2579
protected bool $includeIndex = false;
2680

2781
/**
@@ -38,7 +92,7 @@ public function __construct($results, array $columnDef, array $templates, int $s
3892
$this->excessColumns = $columnDef['excess'] ?? [];
3993
$this->onlyColumns = $columnDef['only'] ?? [];
4094
$this->escapeColumns = $columnDef['escape'] ?? [];
41-
$this->includeIndex = $columnDef['index'] ?? [];
95+
$this->includeIndex = $columnDef['index'] ?? false;
4296
$this->rawColumns = $columnDef['raw'] ?? [];
4397
$this->makeHidden = $columnDef['hidden'] ?? [];
4498
$this->makeVisible = $columnDef['visible'] ?? [];
@@ -79,7 +133,7 @@ public function process($object = false): array
79133
* Process add columns.
80134
*
81135
* @param array $data
82-
* @param array|object $row
136+
* @param array|object|\Illuminate\Database\Eloquent\Model $row
83137
* @return array
84138
*/
85139
protected function addColumns(array $data, $row): array
@@ -89,8 +143,9 @@ protected function addColumns(array $data, $row): array
89143
if ($content instanceof Formatter) {
90144
$column = str_replace('_formatted', '', $value['name']);
91145

92-
/** @phpstan-ignore-next-line */
93-
$value['content'] = $content->format($data[$column], $row);
146+
if (isset($data[$column])) {
147+
$value['content'] = $content->format($data[$column], $row);
148+
}
94149
} else {
95150
$value['content'] = Helper::compileContent($content, $data, $row);
96151
}

0 commit comments

Comments
 (0)