Skip to content

Commit 3b9f565

Browse files
hamidrezarjgithub-actions[bot]
authored andcommitted
Fix styling
1 parent ef7df68 commit 3b9f565

23 files changed

+67
-103
lines changed

src/DataTableInput.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@
77

88
class DataTableInput
99
{
10-
/**
11-
* @param int $start
12-
* @param int $size
13-
* @param array $filters
14-
* @param array $sorting
15-
* @param array $rels
16-
*/
1710
public function __construct(
18-
private int $start,
19-
private ?int $size,
11+
private int $start,
12+
private ?int $size,
2013
private array $filters,
2114
private array $sorting,
2215
private array $rels,
2316
private array $allowedFilters,
2417
private array $allowedSortings,
25-
)
26-
{
18+
) {
2719
}
2820

2921
public function getStart(): int
@@ -41,7 +33,7 @@ public function getSize(): ?int
4133
*/
4234
public function getFilters(): array
4335
{
44-
$filters = array();
36+
$filters = [];
4537

4638
foreach ($this->filters as $filter) {
4739
$filters[] = new Filter(
@@ -56,19 +48,14 @@ public function getFilters(): array
5648
return $filters;
5749
}
5850

59-
/**
60-
* @return Sort|null
61-
*/
6251
public function getSorting(): ?Sort
6352
{
64-
return !empty($this->sorting) ?
53+
return ! empty($this->sorting) ?
6554
new Sort($this->sorting[0]->id, $this->sorting[0]->desc, $this->allowedSortings) : null;
6655
}
6756

6857
public function getRelations(): array
6958
{
7059
return $this->rels;
7160
}
72-
73-
7461
}

src/DataTableService.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,64 @@
88

99
class DataTableService
1010
{
11-
1211
protected array $allowedFilters;
12+
1313
protected array $allowedRelations;
14+
1415
protected array $allowedSortings;
16+
1517
protected array $allowedSelects;
18+
1619
private int $totalRowCount;
1720

1821
public function __construct(
19-
protected Builder $query,
22+
protected Builder $query,
2023
private DataTableInput $dataTableInput
21-
)
22-
{
24+
) {
2325
}
2426

2527
public function setAllowedFilters(array $allowedFilters): DataTableService
2628
{
2729
$this->allowedFilters = $allowedFilters;
30+
2831
return $this;
2932
}
3033

3134
public function setAllowedRelations(array $allowedRelations): DataTableService
3235
{
3336
$this->allowedRelations = $allowedRelations;
37+
3438
return $this;
3539
}
3640

3741
public function setAllowedSortings(array $allowedSortings): DataTableService
3842
{
3943
$this->allowedSortings = $allowedSortings;
44+
4045
return $this;
4146
}
4247

4348
public function setAllowedSelects(array $allowedSelects): DataTableService
4449
{
4550
$this->allowedSelects = $allowedSelects;
51+
4652
return $this;
4753
}
4854

4955
/**
5056
* Handle 'getData' operations
51-
* @return array
5257
*/
5358
public function getData(): array
5459
{
5560
$query = $this->buildQuery();
5661
$data = $query->get();
5762

58-
return array(
63+
return [
5964
'data' => $data,
6065
'meta' => [
61-
'totalRowCount' => $this->totalRowCount
62-
]
63-
);
66+
'totalRowCount' => $this->totalRowCount,
67+
],
68+
];
6469
}
6570

6671
protected function buildQuery(): Builder
@@ -78,18 +83,19 @@ protected function buildQuery(): Builder
7883

7984
$query->offset($this->dataTableInput->getStart());
8085

81-
if(!is_null($this->dataTableInput->getSize())){
86+
if (! is_null($this->dataTableInput->getSize())) {
8287
$query->limit($this->dataTableInput->getSize());
8388
}
8489

8590
$sorting = $this->dataTableInput->getSorting();
8691
$query = (new ApplySort($query, $sorting))->apply();
92+
8793
return $query;
8894
}
8995

9096
protected function applySelect(Builder $query, array $selectedFields): Builder
9197
{
92-
if (!empty($selectedFields)) {
98+
if (! empty($selectedFields)) {
9399
$query->select($selectedFields);
94100
}
95101

@@ -98,7 +104,7 @@ protected function applySelect(Builder $query, array $selectedFields): Builder
98104

99105
protected function includeRelationsInQuery(Builder $query, array $rels): Builder
100106
{
101-
if (!empty($rels)) {
107+
if (! empty($rels)) {
102108
$query->with($rels);
103109
}
104110

src/Enums/DataType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace HamidRrj\LaravelDatatable\Enums;
4+
45
enum DataType: string
56
{
67
case NUMERIC = 'numeric';
@@ -9,6 +10,6 @@ enum DataType: string
910

1011
public static function values(): array
1112
{
12-
return array_column(self::cases(), 'value');
13+
return array_column(self::cases(), 'value');
1314
}
1415
}

src/Enums/SearchType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ enum SearchType: string
1414

1515
public static function values(): array
1616
{
17-
return array_column(self::cases(), 'value');
17+
return array_column(self::cases(), 'value');
1818
}
19-
}
19+
}

src/Exceptions/InvalidFilterException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InvalidFilterException extends Exception implements InvalidParameterInterf
88
{
99
protected $fieldName;
1010

11-
public function __construct($fieldName, $message = "", $code = 400, \Throwable $previous = null)
11+
public function __construct($fieldName, $message = '', $code = 400, ?\Throwable $previous = null)
1212
{
1313
$this->fieldName = $fieldName;
1414
parent::__construct($message, $code, $previous);

src/Exceptions/InvalidRelationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InvalidRelationException extends Exception implements InvalidParameterInte
88
{
99
protected $fieldName;
1010

11-
public function __construct($fieldName, $message = "", $code = 400, \Throwable $previous = null)
11+
public function __construct($fieldName, $message = '', $code = 400, ?\Throwable $previous = null)
1212
{
1313
$this->fieldName = $fieldName;
1414
parent::__construct($message, $code, $previous);

src/Exceptions/InvalidSortingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class InvalidSortingException extends Exception implements InvalidParameterInter
88
{
99
protected $fieldName;
1010

11-
public function __construct($fieldName, $message = "", $code = 400, \Throwable $previous = null)
11+
public function __construct($fieldName, $message = '', $code = 400, ?\Throwable $previous = null)
1212
{
1313
$this->fieldName = $fieldName;
1414
parent::__construct($message, $code, $previous);

src/Filter/ApplyFilter.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ class ApplyFilter
1717
{
1818
private SearchFilter $searchFilter;
1919

20-
/**
21-
* @param Builder $query
22-
* @param Filter $filter
23-
*/
2420
public function __construct(
2521
private Builder $query,
26-
private Filter $filter,
27-
)
28-
{
22+
private Filter $filter,
23+
) {
2924
}
3025

3126
public function apply(): Builder
@@ -62,10 +57,10 @@ public function apply(): Builder
6257
default:
6358
$searchFunction = $filter->getFn();
6459
throw new InvalidFilterException($searchFunction, "search function `$searchFunction` is invalid.");
65-
6660
}
6761

6862
$relation = $this->filter->getRelation();
63+
6964
return $relation ? $this->applyFilterToRelation($relation) : $this->searchFilter->apply();
7065
}
7166

src/Filter/Filter.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ class Filter
99
private static FilterValidator $filterValidator;
1010

1111
/**
12-
* @param string $id
13-
* @param string|int|array $value
14-
* @param string $fn
15-
* @param string $datatype
16-
* @param array $allowedFilters
1712
* @throws \HamidRrj\LaravelDatatable\Exceptions\InvalidFilterException
1813
*/
1914
public function __construct(
20-
private string $id,
15+
private string $id,
2116
private string|int|array $value,
22-
private string $fn,
23-
private string $datatype,
17+
private string $fn,
18+
private string $datatype,
2419
private array $allowedFilters
25-
)
26-
{
20+
) {
2721
self::$filterValidator = FilterValidator::getInstance();
2822
self::$filterValidator->isValid($this, $this->allowedFilters);
2923
}
@@ -51,12 +45,14 @@ public function getDatatype(): string
5145
public function getRelation(): string
5246
{
5347
$fieldArray = explode('.', $this->id);
48+
5449
return count($fieldArray) > 1 ? $fieldArray[0] : '';
5550
}
5651

5752
public function getColumn(): string
5853
{
5954
$fieldArray = explode('.', $this->id);
55+
6056
return array_pop($fieldArray);
6157
}
6258

@@ -69,5 +65,4 @@ public function setValue(int|array|string $value): void
6965
{
7066
$this->value = $value;
7167
}
72-
7368
}

src/Filter/SearchFunctions/FilterBetween.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class FilterBetween extends SearchFilter
88
{
9-
109
public function apply(): Builder
1110
{
1211
$query = $this->query;

0 commit comments

Comments
 (0)