Skip to content

Commit

Permalink
Merge pull request #3108 from yajra/analysis-b06GGa
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
yajra committed Dec 27, 2023
2 parents d110a78 + 33429b0 commit 45dbcfd
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 202 deletions.
20 changes: 10 additions & 10 deletions src/DataTableAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ abstract class DataTableAbstract implements DataTable
* @var array
*/
protected array $templates = [
'DT_RowId' => '',
'DT_RowId' => '',
'DT_RowClass' => '',
'DT_RowData' => [],
'DT_RowAttr' => [],
'DT_RowData' => [],
'DT_RowAttr' => [],
];

/**
Expand Down Expand Up @@ -920,10 +920,10 @@ protected function processResults($results, $object = false): array
protected function render(array $data): JsonResponse
{
$output = $this->attachAppends([
'draw' => $this->request->draw(),
'recordsTotal' => $this->totalRecords,
'draw' => $this->request->draw(),
'recordsTotal' => $this->totalRecords,
'recordsFiltered' => $this->filteredRecords ?? 0,
'data' => $data,
'data' => $data,
]);

if ($this->config->isDebugging()) {
Expand Down Expand Up @@ -987,11 +987,11 @@ protected function errorResponse(\Exception $exception)
$this->getLogger()->error($exception);

return new JsonResponse([
'draw' => $this->request->draw(),
'recordsTotal' => $this->totalRecords,
'draw' => $this->request->draw(),
'recordsTotal' => $this->totalRecords,
'recordsFiltered' => 0,
'data' => [],
'error' => $error ? __($error) : "Exception Message:\n\n".$exception->getMessage(),
'data' => [],
'error' => $error ? __($error) : "Exception Message:\n\n".$exception->getMessage(),
]);
}

Expand Down
34 changes: 17 additions & 17 deletions src/config/datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
/*
* DataTables search options.
*/
'search' => [
'search' => [
/*
* Smart search will enclose search keyword with wildcard string "%keyword%".
* SQL: column LIKE "%keyword%"
*/
'smart' => true,
'smart' => true,

/*
* Multi-term search will explode search keyword using spaces resulting into multiple term search.
*/
'multi_term' => true,
'multi_term' => true,

/*
* Case insensitive will search the keyword in lower case format.
Expand All @@ -26,27 +26,27 @@
* Wild card will add "%" in between every characters of the keyword.
* SQL: column LIKE "%k%e%y%w%o%r%d%"
*/
'use_wildcards' => false,
'use_wildcards' => false,

/*
* Perform a search which starts with the given keyword.
* SQL: column LIKE "keyword%"
*/
'starts_with' => false,
'starts_with' => false,
],

/*
* DataTables internal index id response column name.
*/
'index_column' => 'DT_RowIndex',
'index_column' => 'DT_RowIndex',

/*
* List of available builders for DataTables.
* This is where you can register your custom dataTables builder.
*/
'engines' => [
'eloquent' => Yajra\DataTables\EloquentDataTable::class,
'query' => Yajra\DataTables\QueryDataTable::class,
'engines' => [
'eloquent' => Yajra\DataTables\EloquentDataTable::class,
'query' => Yajra\DataTables\QueryDataTable::class,
'collection' => Yajra\DataTables\CollectionDataTable::class,
'resource' => Yajra\DataTables\ApiResourceDataTable::class,
],
Expand All @@ -56,7 +56,7 @@
* This is where you can override which engine a builder should use
* Note, only change this if you know what you are doing!
*/
'builders' => [
'builders' => [
//Illuminate\Database\Eloquent\Relations\Relation::class => 'eloquent',
//Illuminate\Database\Eloquent\Builder::class => 'eloquent',
//Illuminate\Database\Query\Builder::class => 'query',
Expand All @@ -76,28 +76,28 @@
* 'throw' - Throws a \Yajra\DataTables\Exceptions\Exception. Use your custom error handler if needed.
* 'custom message' - Any friendly message to be displayed to the user. You can also use translation key.
*/
'error' => env('DATATABLES_ERROR', null),
'error' => env('DATATABLES_ERROR', null),

/*
* Default columns definition of dataTable utility functions.
*/
'columns' => [
'columns' => [
/*
* List of columns hidden/removed on json response.
*/
'excess' => ['rn', 'row_num'],
'excess' => ['rn', 'row_num'],

/*
* List of columns to be escaped. If set to *, all columns are escape.
* Note: You can set the value to empty array to disable XSS protection.
*/
'escape' => '*',
'escape' => '*',

/*
* List of columns that are allowed to display html content.
* Note: Adding columns to list will make us available to XSS attacks.
*/
'raw' => ['action'],
'raw' => ['action'],

/*
* List of columns are forbidden from being searched/sorted.
Expand All @@ -114,8 +114,8 @@
/*
* JsonResponse header and options config.
*/
'json' => [
'header' => [],
'json' => [
'header' => [],
'options' => 0,
],

Expand Down
2 changes: 1 addition & 1 deletion tests/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function toArray($request)
return [
// 'id' => $this->id,
'email' => $this->email,
'name' => $this->name,
'name' => $this->name,
];
}
}
18 changes: 9 additions & 9 deletions tests/Integration/BelongsToManyRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function it_returns_all_records_with_the_relation_when_called_without_par
{
$response = $this->call('GET', '/relations/belongsToMany');
$response->assertJson([
'draw' => 0,
'recordsTotal' => 20,
'draw' => 0,
'recordsTotal' => 20,
'recordsFiltered' => 20,
]);

Expand All @@ -33,8 +33,8 @@ public function it_can_perform_global_search_on_the_relation()
]);

$response->assertJson([
'draw' => 0,
'recordsTotal' => 20,
'draw' => 0,
'recordsTotal' => 20,
'recordsFiltered' => 10,
]);

Expand All @@ -61,17 +61,17 @@ public function it_can_sort_using_the_relation_with_pagination()
'order' => [
[
'column' => 2,
'dir' => 'desc',
'dir' => 'desc',
],
],
'length' => 10,
'start' => 0,
'draw' => 1,
'start' => 0,
'draw' => 1,
]);

$response->assertJson([
'draw' => 1,
'recordsTotal' => 20,
'draw' => 1,
'recordsTotal' => 20,
'recordsFiltered' => 20,
]);

Expand Down
18 changes: 9 additions & 9 deletions tests/Integration/BelongsToRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function it_returns_all_records_with_the_relation_when_called_without_par
{
$response = $this->call('GET', '/relations/belongsTo');
$response->assertJson([
'draw' => 0,
'recordsTotal' => 60,
'draw' => 0,
'recordsTotal' => 60,
'recordsFiltered' => 60,
]);

Expand All @@ -33,8 +33,8 @@ public function it_can_perform_global_search_on_the_relation()
]);

$response->assertJson([
'draw' => 0,
'recordsTotal' => 60,
'draw' => 0,
'recordsTotal' => 60,
'recordsFiltered' => 3,
]);

Expand All @@ -61,17 +61,17 @@ public function it_can_sort_using_the_relation_with_pagination()
'order' => [
[
'column' => 1,
'dir' => 'desc',
'dir' => 'desc',
],
],
'length' => 10,
'start' => 0,
'draw' => 1,
'start' => 0,
'draw' => 1,
]);

$response->assertJson([
'draw' => 1,
'recordsTotal' => 60,
'draw' => 1,
'recordsTotal' => 60,
'recordsFiltered' => 60,
]);

Expand Down
46 changes: 23 additions & 23 deletions tests/Integration/CollectionDataTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function it_returns_all_records_when_no_parameters_is_passed()
{
$crawler = $this->call('GET', '/collection/users');
$crawler->assertJson([
'draw' => 0,
'recordsTotal' => 20,
'draw' => 0,
'recordsTotal' => 20,
'recordsFiltered' => 20,
]);
}
Expand All @@ -33,7 +33,7 @@ public function it_returns_zero_filtered_records_on_empty_collection()
'data' => [],
'draw' => 0,
'input' => [],
'recordsTotal' => 0,
'recordsTotal' => 0,
'recordsFiltered' => 0,
]);
}
Expand All @@ -50,8 +50,8 @@ public function it_can_perform_global_search()
]);

$crawler->assertJson([
'draw' => 0,
'recordsTotal' => 20,
'draw' => 0,
'recordsTotal' => 20,
'recordsFiltered' => 1,
]);
}
Expand Down Expand Up @@ -109,10 +109,10 @@ public function it_can_sort_case_insensitive_strings()
'columns' => [
['data' => 'name', 'name' => 'name', 'searchable' => 'true', 'orderable' => 'true'],
],
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'length' => 10,
'draw' => 1,
'draw' => 1,
]);

$collection = collect([
Expand All @@ -129,10 +129,10 @@ public function it_can_sort_case_insensitive_strings()
$response = $dataTable->toJson();

$this->assertEquals([
'draw' => 1,
'recordsTotal' => 6,
'draw' => 1,
'recordsTotal' => 6,
'recordsFiltered' => 6,
'data' => [
'data' => [
['name' => 'aaa'],
['name' => 'ABC'],
['name' => 'bbb'],
Expand All @@ -151,10 +151,10 @@ public function it_can_sort_numeric_strings()
'columns' => [
['data' => 'amount', 'name' => 'amount', 'searchable' => 'true', 'orderable' => 'true'],
],
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'length' => 10,
'draw' => 1,
'draw' => 1,
]);

$collection = collect([
Expand All @@ -171,10 +171,10 @@ public function it_can_sort_numeric_strings()
$response = $dataTable->toJson();

$this->assertEquals([
'draw' => 1,
'recordsTotal' => 6,
'draw' => 1,
'recordsTotal' => 6,
'recordsFiltered' => 6,
'data' => [
'data' => [
['amount' => '-8'],
['amount' => '-3'],
['amount' => '0'],
Expand Down Expand Up @@ -203,13 +203,13 @@ public function it_can_search_on_added_columns()
['data' => 'name', 'name' => 'name', 'searchable' => 'true', 'orderable' => 'true'],
['data' => 'foo', 'name' => 'foo', 'searchable' => 'true', 'orderable' => 'true'],
],
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'search' => [
'value' => 'bar aaa',
],
'length' => 10,
'draw' => 1,
'draw' => 1,
]);

$collection = collect([
Expand All @@ -226,10 +226,10 @@ public function it_can_search_on_added_columns()
$response = $dataTable->addColumn('foo', 'bar {{$name}}')->toJson();

$this->assertEquals([
'draw' => 1,
'recordsTotal' => 6,
'draw' => 1,
'recordsTotal' => 6,
'recordsFiltered' => 1,
'data' => [
'data' => [
['name' => 'aaa', 'foo' => 'bar aaa'],
],
], $response->getData(true));
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/CustomOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function it_can_order_with_custom_order()
'order' => [
[
'column' => 0,
'dir' => 'asc',
'dir' => 'asc',
],
],
]);
Expand All @@ -36,9 +36,9 @@ protected function getJsonResponse(array $params = [])
['data' => 'user.id', 'name' => 'user.id', 'searchable' => 'true', 'orderable' => 'true'],
['data' => 'title', 'name' => 'posts.title', 'searchable' => 'true', 'orderable' => 'true'],
],
'length' => 10,
'start' => 0,
'draw' => 1,
'length' => 10,
'start' => 0,
'draw' => 1,
];

return $this->call(
Expand Down
Loading

0 comments on commit 45dbcfd

Please sign in to comment.