Skip to content

Commit dd786ec

Browse files
committed
PHPStan level 8
1 parent 89f3511 commit dd786ec

File tree

7 files changed

+91
-74
lines changed

7 files changed

+91
-74
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ parameters:
66
paths:
77
- src
88

9-
level: 5
9+
level: 8
1010

1111
ignoreErrors:
1212
- '#Unsafe usage of new static\(\).#'

src/ButtonsServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function boot(): void
2727
/**
2828
* Publish datatables assets.
2929
*/
30-
protected function publishAssets()
30+
protected function publishAssets(): void
3131
{
3232
$this->publishes([
3333
__DIR__.'/config/config.php' => config_path('datatables-buttons.php'),
@@ -45,7 +45,7 @@ protected function publishAssets()
4545
/**
4646
* Register datatables commands.
4747
*/
48-
protected function registerCommands()
48+
protected function registerCommands(): void
4949
{
5050
$this->commands(DataTablesMakeCommand::class);
5151
$this->commands(DataTablesScopeCommand::class);

src/Exports/DataTablesCollectionExport.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ abstract class DataTablesCollectionExport implements FromCollection, WithHeading
1414
/**
1515
* @var Collection
1616
*/
17-
protected $collection;
17+
protected Collection $collection;
1818

1919
/**
20-
* @param Collection $collection
20+
* @param \Illuminate\Support\Collection|null $collection
2121
*/
22-
public function __construct(Collection $collection)
22+
public function __construct(Collection $collection = null)
2323
{
24-
$this->collection = $collection;
24+
$this->collection = $collection ?? new Collection;
2525
}
2626

2727
/**
2828
* @return Collection
2929
*/
30-
public function collection()
30+
public function collection(): Collection
3131
{
3232
return $this->collection;
3333
}

src/Generators/DataTablesHtmlCommand.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ protected function buildClass($name)
6262
*/
6363
protected function getStub(): string
6464
{
65-
$config = $this->laravel['config'];
66-
67-
return $config->get('datatables-buttons.stub')
68-
? base_path() . $config->get('datatables-buttons.stub') . '/html.stub'
69-
: __DIR__ . '/stubs/html.stub';
65+
return config('datatables-buttons.stub')
66+
? base_path().config('datatables-buttons.stub').'/html.stub'
67+
: __DIR__.'/stubs/html.stub';
7068
}
7169

7270
/**
@@ -91,6 +89,6 @@ protected function qualifyClass($name): string
9189
$name .= 'DataTableHtml';
9290
}
9391

94-
return $this->getDefaultNamespace(trim($rootNamespace, '\\')) . '\\' . $name;
92+
return $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name;
9593
}
9694
}

src/Generators/DataTablesMakeCommand.php

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,15 @@ public function handle()
4343
parent::handle();
4444

4545
if ($this->option('builder')) {
46+
$columns = config('datatables-buttons.generator.columns', 'id,add your columns,created_at,updated_at');
47+
$buttons = config('datatables-buttons.generator.buttons', 'create,export,print,reset,reload');
48+
$dom = config('datatables-buttons.generator.dom', 'Bfrtip');
49+
4650
$this->call('datatables:html', [
4751
'name' => $this->getNameInput(),
48-
'--columns' => $this->option('columns') ?: $this->laravel['config']->get(
49-
'datatables-buttons.generator.columns',
50-
'id,add your columns,created_at,updated_at'
51-
),
52-
'--buttons' => $this->option('buttons') ?: $this->laravel['config']->get(
53-
'datatables-buttons.generator.buttons',
54-
'create,export,print,reset,reload'
55-
),
56-
'--dom' => $this->option('dom') ?: $this->laravel['config']->get(
57-
'datatables-buttons.generator.dom',
58-
'Bfrtip'
59-
),
52+
'--columns' => $this->option('columns') ?: $columns,
53+
'--buttons' => $this->option('buttons') ?: $buttons,
54+
'--dom' => $this->option('dom') ?: $dom,
6055
'--table' => $this->option('table'),
6156
]);
6257
}
@@ -95,7 +90,9 @@ protected function buildClass($name)
9590
protected function replaceFilename(string &$stub): static
9691
{
9792
$stub = str_replace(
98-
'DummyFilename', preg_replace('#datatable$#i', '', $this->getNameInput()), $stub
93+
'DummyFilename',
94+
(string) preg_replace('#datatable$#i', '', $this->getNameInput()),
95+
$stub
9996
);
10097

10198
return $this;
@@ -123,7 +120,14 @@ protected function replaceAction(string &$stub): static
123120
*/
124121
protected function getAction(): string
125122
{
126-
return $this->option('action') ?: Str::lower($this->getNameInput()).'.action';
123+
/** @var string $action */
124+
$action = $this->option('action');
125+
126+
if ($action) {
127+
return $action;
128+
}
129+
130+
return Str::lower($this->getNameInput()).'.action';
127131
}
128132

129133
/**
@@ -151,7 +155,7 @@ protected function replaceDOM(string &$stub): static
151155
{
152156
$stub = str_replace(
153157
'DummyDOM',
154-
$this->option('dom') ?: $this->laravel['config']->get('datatables-buttons.generator.dom', 'Bfrtip'),
158+
$this->option('dom') ?: config('datatables-buttons.generator.dom', 'Bfrtip'),
155159
$stub
156160
);
157161

@@ -180,16 +184,19 @@ protected function replaceButtons(string &$stub): static
180184
*/
181185
protected function getButtons(): string
182186
{
183-
if ($this->option('buttons') != '') {
184-
return $this->parseButtons($this->option('buttons'));
185-
} else {
186-
return $this->parseButtons(
187-
$this->laravel['config']->get(
188-
'datatables-buttons.generator.buttons',
189-
'create,export,print,reset,reload'
190-
)
191-
);
187+
/** @var string $buttons */
188+
$buttons = $this->option('buttons');
189+
190+
if ($buttons) {
191+
return $this->parseButtons($buttons);
192192
}
193+
194+
return $this->parseButtons(
195+
config(
196+
'datatables-buttons.generator.buttons',
197+
'create,export,print,reset,reload'
198+
)
199+
);
193200
}
194201

195202
/**
@@ -243,22 +250,23 @@ protected function replaceColumns(string &$stub): static
243250
*/
244251
protected function getColumns(): string
245252
{
253+
/** @var string $table */
246254
$table = $this->option('table');
247255

248256
if ($table) {
249257
return $this->parseColumns(Schema::getColumnListing($table));
250258
}
251259

252-
if ($this->option('columns') != '') {
253-
return $this->parseColumns($this->option('columns'));
260+
/** @var string $columns */
261+
$columns = $this->option('columns');
262+
263+
if ($columns) {
264+
return $this->parseColumns($columns);
254265
}
255266

256-
return $this->parseColumns(
257-
$this->laravel['config']->get(
258-
'datatables-buttons.generator.columns',
259-
'id,add your columns,created_at,updated_at'
260-
)
261-
);
267+
$columns = config('datatables-buttons.generator.columns', 'id,add your columns,created_at,updated_at');
268+
269+
return $this->parseColumns($columns);
262270
}
263271

264272
/**
@@ -332,7 +340,7 @@ protected function qualifyClass($name)
332340
*/
333341
protected function getDefaultNamespace($rootNamespace): string
334342
{
335-
return $rootNamespace.'\\'.$this->laravel['config']->get('datatables-buttons.namespace.base', 'DataTables');
343+
return $rootNamespace.'\\'.config('datatables-buttons.namespace.base', 'DataTables');
336344
}
337345

338346
/**
@@ -359,11 +367,15 @@ protected function getModel(): string
359367
{
360368
$name = $this->getNameInput();
361369
$rootNamespace = $this->laravel->getNamespace();
362-
$model = $this->option('model') == '' || $this->option('model-namespace');
363-
$modelNamespace = $this->option('model-namespace') ? $this->option('model-namespace') : $this->laravel['config']->get('datatables-buttons.namespace.model');
364370

365-
if ($this->option('model') != '') {
366-
return $this->option('model');
371+
/** @var string $modelFromOption */
372+
$modelFromOption = $this->option('model');
373+
374+
$model = $modelFromOption == '' || $this->option('model-namespace');
375+
$modelNamespace = $this->option('model-namespace') ? $this->option('model-namespace') : config('datatables-buttons.namespace.model');
376+
377+
if ($modelFromOption) {
378+
return $modelFromOption;
367379
}
368380

369381
// check if model namespace is not set in command and Models directory already exists then use that directory in namespace.
@@ -398,15 +410,14 @@ protected function replaceModelImport(string &$stub): static
398410
*/
399411
protected function getStub(): string
400412
{
401-
$config = $this->laravel['config'];
402413
$stub = 'datatables.stub';
403414

404415
if ($this->option('builder')) {
405416
$stub = 'builder.stub';
406417
}
407418

408-
return $config->get('datatables-buttons.stub')
409-
? base_path().$config->get('datatables-buttons.stub')."/{$stub}"
419+
return config('datatables-buttons.stub')
420+
? base_path().config('datatables-buttons.stub')."/$stub"
410421
: __DIR__."/stubs/{$stub}";
411422
}
412423
}

src/Generators/DataTablesScopeCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ class DataTablesScopeCommand extends GeneratorCommand
3333
* @param string $rootNamespace
3434
* @return string
3535
*/
36-
protected function getDefaultNamespace($rootNamespace)
36+
protected function getDefaultNamespace($rootNamespace): string
3737
{
38-
return $rootNamespace . '\DataTables\Scopes';
38+
return $rootNamespace.'\DataTables\Scopes';
3939
}
4040

4141
/**
4242
* Get the stub file for the generator.
4343
*
4444
* @return string
4545
*/
46-
protected function getStub()
46+
protected function getStub(): string
4747
{
48-
if ($stubFolder = $this->laravel['config']->get('datatables-buttons.stub')) {
49-
return base_path($stubFolder . '/scopes.stub');
48+
if ($stubFolder = config('datatables-buttons.stub')) {
49+
return base_path($stubFolder.'/scopes.stub');
5050
}
5151

52-
return __DIR__ . '/stubs/scopes.stub';
52+
return __DIR__.'/stubs/scopes.stub';
5353
}
5454
}

0 commit comments

Comments
 (0)