Skip to content

Commit bb87150

Browse files
committed
chore: rector & pint
1 parent 23d1bac commit bb87150

File tree

9 files changed

+121
-102
lines changed

9 files changed

+121
-102
lines changed

composer.json

Lines changed: 74 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,77 @@
11
{
2-
"name": "yajra/laravel-datatables-buttons",
3-
"description": "Laravel DataTables Buttons Plugin.",
4-
"keywords": [
5-
"laravel",
6-
"datatables",
7-
"buttons",
8-
"jquery"
9-
],
10-
"license": "MIT",
11-
"authors": [
12-
{
13-
"name": "Arjay Angeles",
14-
"email": "aqangeles@gmail.com"
15-
}
16-
],
17-
"require": {
18-
"php": "^8.2",
19-
"yajra/laravel-datatables-oracle": "^11",
20-
"yajra/laravel-datatables-html": "^11",
21-
"illuminate/console": "^11"
22-
},
23-
"require-dev": {
24-
"larastan/larastan": "^2.4",
25-
"orchestra/testbench": "^9"
26-
},
27-
"autoload": {
28-
"psr-4": {
29-
"Yajra\\DataTables\\": "src/"
30-
}
31-
},
32-
"autoload-dev": {
33-
"psr-4": {
34-
"Yajra\\DataTables\\Buttons\\Tests\\": "tests/"
35-
}
36-
},
37-
"extra": {
38-
"branch-alias": {
39-
"dev-master": "11.0-dev"
2+
"name": "yajra/laravel-datatables-buttons",
3+
"description": "Laravel DataTables Buttons Plugin.",
4+
"keywords": [
5+
"laravel",
6+
"datatables",
7+
"buttons",
8+
"jquery"
9+
],
10+
"license": "MIT",
11+
"authors": [
12+
{
13+
"name": "Arjay Angeles",
14+
"email": "aqangeles@gmail.com"
15+
}
16+
],
17+
"require": {
18+
"php": "^8.2",
19+
"yajra/laravel-datatables-oracle": "^11",
20+
"yajra/laravel-datatables-html": "^11",
21+
"illuminate/console": "^11"
4022
},
41-
"laravel": {
42-
"providers": [
43-
"Yajra\\DataTables\\ButtonsServiceProvider"
44-
]
45-
}
46-
},
47-
"suggest": {
48-
"yajra/laravel-datatables-export": "Exporting of dataTables (excel, csv and PDF) via livewire and queue worker.",
49-
"maatwebsite/excel": "Exporting of dataTables (excel, csv and PDF) using maatwebsite package.",
50-
"rap2hpoutre/fast-excel": "Faster exporting of dataTables using fast-excel package.",
51-
"dompdf/dompdf": "Allows exporting of dataTable to PDF using the DomPDF.",
52-
"barryvdh/laravel-snappy": "Allows exporting of dataTable to PDF using the print view."
53-
},
54-
"minimum-stability": "dev",
55-
"prefer-stable": true,
56-
"funding": [
57-
{
58-
"type": "github",
59-
"url": "https://github.com/sponsors/yajra"
60-
}
61-
]
23+
"require-dev": {
24+
"larastan/larastan": "^2.4",
25+
"orchestra/testbench": "^9",
26+
"laravel/pint": "^1.14",
27+
"rector/rector": "^1.0",
28+
"maatwebsite/excel": "^3.1"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Yajra\\DataTables\\": "src/"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Yajra\\DataTables\\Buttons\\Tests\\": "tests/"
38+
}
39+
},
40+
"extra": {
41+
"branch-alias": {
42+
"dev-master": "11.0-dev"
43+
},
44+
"laravel": {
45+
"providers": [
46+
"Yajra\\DataTables\\ButtonsServiceProvider"
47+
]
48+
}
49+
},
50+
"suggest": {
51+
"yajra/laravel-datatables-export": "Exporting of dataTables (excel, csv and PDF) via livewire and queue worker.",
52+
"maatwebsite/excel": "Exporting of dataTables (excel, csv and PDF) using maatwebsite package.",
53+
"rap2hpoutre/fast-excel": "Faster exporting of dataTables using fast-excel package.",
54+
"dompdf/dompdf": "Allows exporting of dataTable to PDF using the DomPDF.",
55+
"barryvdh/laravel-snappy": "Allows exporting of dataTable to PDF using the print view."
56+
},
57+
"scripts": {
58+
"test": "./vendor/bin/phpunit",
59+
"pint": "./vendor/bin/pint",
60+
"rector": "./vendor/bin/rector",
61+
"stan": "./vendor/bin/phpstan analyse --memory-limit=2G --ansi --no-progress --no-interaction --configuration=phpstan.neon.dist",
62+
"pr": [
63+
"@pint",
64+
"@rector",
65+
"@stan",
66+
"@test"
67+
]
68+
},
69+
"minimum-stability": "dev",
70+
"prefer-stable": true,
71+
"funding": [
72+
{
73+
"type": "github",
74+
"url": "https://github.com/sponsors/yajra"
75+
}
76+
]
6277
}

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__.'/src',
12+
__DIR__.'/tests',
13+
]);
14+
15+
// register a single rule
16+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17+
18+
// define sets of rules
19+
$rectorConfig->sets([
20+
LevelSetList::UP_TO_PHP_82,
21+
]);
22+
};

src/Exports/DataTablesCollectionExport.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public function __construct($collection = null)
2525
$this->collection = $collection ?? new Collection;
2626
}
2727

28-
/**
29-
* @return Collection|LazyCollection
30-
*/
31-
public function collection()
28+
public function collection(): \Illuminate\Support\Collection|\Illuminate\Support\LazyCollection
3229
{
3330
return $this->collection;
3431
}

src/Generators/DataTablesHtmlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ protected function qualifyClass($name): string
8888
$name = preg_replace('#datatablehtml$#i', 'DataTableHtml', $name);
8989
}
9090

91-
return $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name;
91+
return $this->getDefaultNamespace(trim((string) $rootNamespace, '\\')).'\\'.$name;
9292
}
9393
}

src/Generators/DataTablesMakeCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function buildClass($name): string
8686
*/
8787
protected function getDataTableBaseName(): string
8888
{
89-
return (string) preg_replace('#datatable$#i', '', $this->getNameInput());
89+
return (string) preg_replace('#datatable$#i', '', (string) $this->getNameInput());
9090
}
9191

9292
/**
@@ -311,7 +311,7 @@ protected function qualifyClass($name)
311311
$name = preg_replace('#datatable$#i', 'DataTable', $name);
312312
}
313313

314-
return $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name;
314+
return $this->getDefaultNamespace(trim((string) $rootNamespace, '\\')).'\\'.$name;
315315
}
316316

317317
/**
@@ -343,9 +343,7 @@ protected function getModel(): string
343343
{
344344
/** @var string $modelFromOption */
345345
$modelFromOption = $this->option('model');
346-
$modelNamespaceFromOption = $this->option('model-namespace')
347-
? $this->option('model-namespace')
348-
: config('datatables-buttons.namespace.model');
346+
$modelNamespaceFromOption = $this->option('model-namespace') ?: config('datatables-buttons.namespace.model');
349347

350348
$name = $modelFromOption ?: $this->prepareModelName();
351349
$modelNamespace = $modelNamespaceFromOption ?: $this->laravel->getNamespace();

src/Html/DataTableHtml.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ public static function make(): Builder
2525
}
2626

2727
/**
28-
* @param mixed $parameters
2928
* @return \Yajra\DataTables\Html\Builder
3029
*
3130
* @throws \Exception
3231
*/
33-
public function __call(string $method, $parameters)
32+
public function __call(string $method, mixed $parameters)
3433
{
3534
if (method_exists($this->getHtmlBuilder(), $method)) {
3635
return $this->getHtmlBuilder()->{$method}(...$parameters);

src/Services/DataTable.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function __construct()
168168
public function render(?string $view = null, array $data = [], array $mergeData = [])
169169
{
170170
if ($this->request()->ajax() && $this->request()->wantsJson()) {
171-
return app()->call([$this, 'ajax']);
171+
return app()->call($this->ajax(...));
172172
}
173173

174174
/** @var string $action */
@@ -311,16 +311,12 @@ public function builder(): Builder
311311

312312
/**
313313
* Map ajax response to columns definition.
314-
*
315-
* @param array|Collection $columns
316314
*/
317-
protected function mapResponseToColumns($columns, string $type): array
315+
protected function mapResponseToColumns(array|\Illuminate\Support\Collection $columns, string $type): array
318316
{
319317
$transformer = new DataArrayTransformer;
320318

321-
return array_map(function ($row) use ($columns, $type, $transformer) {
322-
return $transformer->transform($row, $columns, $type);
323-
}, $this->getAjaxResponseData());
319+
return array_map(fn ($row) => $transformer->transform($row, $columns, $type), $this->getAjaxResponseData());
324320
}
325321

326322
/**
@@ -334,7 +330,7 @@ protected function getAjaxResponseData(): array
334330
]);
335331

336332
/** @var JsonResponse $response */
337-
$response = app()->call([$this, 'ajax']);
333+
$response = app()->call($this->ajax(...));
338334

339335
/** @var array{data: array} $data */
340336
$data = $response->getData(true);
@@ -498,7 +494,7 @@ private function toColumnsCollection(array $columns): Collection
498494

499495
foreach ($columns as $column) {
500496
if (isset($column['data'])) {
501-
$column['title'] = $column['title'] ?? $column['data'];
497+
$column['title'] ??= $column['data'];
502498
$collection->push(new Column($column));
503499
} else {
504500
$data = [];
@@ -648,9 +644,7 @@ protected function applyScopes(
648644
*/
649645
protected function hasScopes(array $scopes, bool $validateAll = false): bool
650646
{
651-
$filteredScopes = array_filter($this->scopes, function ($scope) use ($scopes) {
652-
return in_array(get_class($scope), $scopes);
653-
});
647+
$filteredScopes = array_filter($this->scopes, fn ($scope) => in_array($scope::class, $scopes));
654648

655649
return $validateAll ? count($filteredScopes) === count($scopes) : ! empty($filteredScopes);
656650
}

src/Transformers/DataArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function buildColumnByCollection(array $row, Collection $columns, stri
4343

4444
if ($type == 'exportable') {
4545
$title = $this->decodeContent($title);
46-
$data = is_array($data) ? json_encode($data) : $this->decodeContent($data);
46+
$data = is_array($data) ? json_encode($data, JSON_THROW_ON_ERROR) : $this->decodeContent($data);
4747
}
4848

4949
if (isset($column->exportRender)) {

tests/DataTableServiceTest.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,17 @@ protected function setUp(): void
8585
parent::setUp();
8686

8787
$router = $this->app['router'];
88-
$router->get('/users', function (UsersDataTable $dataTable) {
89-
return $dataTable->render('tests::users');
90-
});
91-
92-
$router->get('/users/before', function (UsersDataTable $dataTable) {
93-
return $dataTable->before(function (EloquentDataTable $dataTable) {
94-
$dataTable->addColumn('nameX', fn (User $user) => $user->name.'X');
95-
})->render('tests::users');
96-
});
97-
98-
$router->get('/users/response', function (UsersDataTable $dataTable) {
99-
return $dataTable->response(function (Collection $data) {
100-
$data['recordsTotal'] = 2;
101-
$data['recordsFiltered'] = 1;
102-
103-
return $data;
104-
})->render('tests::users');
105-
});
88+
$router->get('/users', fn (UsersDataTable $dataTable) => $dataTable->render('tests::users'));
89+
90+
$router->get('/users/before', fn (UsersDataTable $dataTable) => $dataTable->before(function (EloquentDataTable $dataTable) {
91+
$dataTable->addColumn('nameX', fn (User $user) => $user->name.'X');
92+
})->render('tests::users'));
93+
94+
$router->get('/users/response', fn (UsersDataTable $dataTable) => $dataTable->response(function (Collection $data) {
95+
$data['recordsTotal'] = 2;
96+
$data['recordsFiltered'] = 1;
97+
98+
return $data;
99+
})->render('tests::users'));
106100
}
107101
}

0 commit comments

Comments
 (0)