@@ -37,7 +37,7 @@ |
||
37 | 37 | */ |
38 | 38 | private function registerMacros() |
39 | 39 | { |
40 | - Builder::macro('sortViaRequest', function ($request) { |
|
40 | + Builder::macro('sortViaRequest', function($request) { |
|
41 | 41 | $handler = new EloquentSortingHandler($request, $this); |
42 | 42 | |
43 | 43 | return $handler->handle(); |
@@ -50,7 +50,7 @@ |
||
50 | 50 | $this->files->put($path, $this->buildClass($name)); |
51 | 51 | } |
52 | 52 | |
53 | - $this->info($this->type.' created successfully.'); |
|
53 | + $this->info($this->type . ' created successfully.'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $this->checkForTrait(); |
42 | 42 | |
43 | 43 | // Loop through every rule and handle it individually |
44 | - foreach($this->rules as $rule) |
|
44 | + foreach ($this->rules as $rule) |
|
45 | 45 | { |
46 | 46 | // Find the relevant sortable column for this rule |
47 | 47 | $sortableColumn = $this->sortableColumns->find($rule['column']); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | private function checkForTrait() |
76 | 76 | { |
77 | - if(!method_exists($this->request, 'validatedSortingRules')) { |
|
77 | + if (!method_exists($this->request, 'validatedSortingRules')) { |
|
78 | 78 | $requestClass = get_class($this->request); |
79 | 79 | |
80 | 80 | throw new EloquentSortingException("{$requestClass} is not using the SortsViaRequest trait."); |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | // Go through the value and take out all the rules |
42 | 42 | $rules = []; |
43 | 43 | |
44 | - while($rule = $this->takeNextSortRule($value)) { |
|
44 | + while ($rule = $this->takeNextSortRule($value)) { |
|
45 | 45 | $rules[] = $rule; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // Fail the validation if no rules were passed |
49 | - if(!count($rules)) |
|
49 | + if (!count($rules)) |
|
50 | 50 | return $this->fail('The :attribute contains no valid sorting rules.'); |
51 | 51 | |
52 | - foreach($rules as $rule) { |
|
52 | + foreach ($rules as $rule) { |
|
53 | 53 | $column = $rule['column']; |
54 | 54 | $direction = $rule['direction']; |
55 | 55 | |
56 | 56 | // Validate that the column can be sorted on |
57 | - if(!$this->sortableColumns->isValidColumn($column)) |
|
57 | + if (!$this->sortableColumns->isValidColumn($column)) |
|
58 | 58 | return $this->fail("'{$column}' cannot be sorted on."); |
59 | 59 | |
60 | 60 | // Validate that the direction is valid |
61 | - if(!$this->sortableColumns->isValidDirectionForColumn($column, $direction)) |
|
61 | + if (!$this->sortableColumns->isValidDirectionForColumn($column, $direction)) |
|
62 | 62 | return $this->fail("'{$direction}' is an invalid sorting direction for '{$column}'"); |
63 | 63 | |
64 | 64 | // Validate whether the column is not present more than once |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | return ($rule['column'] == $column); |
67 | 67 | }); |
68 | 68 | |
69 | - if(count($doubleRule) > 1) |
|
69 | + if (count($doubleRule) > 1) |
|
70 | 70 | return $this->fail("'{$direction}' should only have one sort rule."); |
71 | 71 | } |
72 | 72 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function takeNextSortRule(&$subject) |
107 | 107 | { |
108 | - if(preg_match(self::SORT_PATTERN, $subject, $match)) |
|
108 | + if (preg_match(self::SORT_PATTERN, $subject, $match)) |
|
109 | 109 | { |
110 | 110 | // Remove the match from the string |
111 | 111 | $subject = preg_replace(self::SORT_PATTERN, '', $subject, 1); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | $collection = new SortableColumnCollection(); |
131 | 131 | |
132 | - foreach($columns as $left => $right) { |
|
132 | + foreach ($columns as $left => $right) { |
|
133 | 133 | // ['columnName' => Sorter::class]; notation |
134 | 134 | if (is_string($left)) { |
135 | 135 | // Redefine variables for clarity |
@@ -46,28 +46,32 @@ |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | // Fail the validation if no rules were passed |
49 | - if(!count($rules)) |
|
50 | - return $this->fail('The :attribute contains no valid sorting rules.'); |
|
49 | + if(!count($rules)) { |
|
50 | + return $this->fail('The :attribute contains no valid sorting rules.'); |
|
51 | + } |
|
51 | 52 | |
52 | 53 | foreach($rules as $rule) { |
53 | 54 | $column = $rule['column']; |
54 | 55 | $direction = $rule['direction']; |
55 | 56 | |
56 | 57 | // Validate that the column can be sorted on |
57 | - if(!$this->sortableColumns->isValidColumn($column)) |
|
58 | - return $this->fail("'{$column}' cannot be sorted on."); |
|
58 | + if(!$this->sortableColumns->isValidColumn($column)) { |
|
59 | + return $this->fail("'{$column}' cannot be sorted on."); |
|
60 | + } |
|
59 | 61 | |
60 | 62 | // Validate that the direction is valid |
61 | - if(!$this->sortableColumns->isValidDirectionForColumn($column, $direction)) |
|
62 | - return $this->fail("'{$direction}' is an invalid sorting direction for '{$column}'"); |
|
63 | + if(!$this->sortableColumns->isValidDirectionForColumn($column, $direction)) { |
|
64 | + return $this->fail("'{$direction}' is an invalid sorting direction for '{$column}'"); |
|
65 | + } |
|
63 | 66 | |
64 | 67 | // Validate whether the column is not present more than once |
65 | 68 | $doubleRule = array_filter($rules, function($rule) use($column) { |
66 | 69 | return ($rule['column'] == $column); |
67 | 70 | }); |
68 | 71 | |
69 | - if(count($doubleRule) > 1) |
|
70 | - return $this->fail("'{$direction}' should only have one sort rule."); |
|
72 | + if(count($doubleRule) > 1) { |
|
73 | + return $this->fail("'{$direction}' should only have one sort rule."); |
|
74 | + } |
|
71 | 75 | } |
72 | 76 | |
73 | 77 | $this->sortingRules = $rules; |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $column = $this->find($column); |
32 | 32 | |
33 | - if($column) { |
|
33 | + if ($column) { |
|
34 | 34 | return in_array($direction, $column->sorter->getDirections()); |
35 | 35 | } |
36 | 36 | |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | */ |
46 | 46 | function find($column) |
47 | 47 | { |
48 | - foreach($this->items as $item) { |
|
49 | - if($item->name === $column) return $item; |
|
48 | + foreach ($this->items as $item) { |
|
49 | + if ($item->name === $column) return $item; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return null; |
@@ -46,7 +46,9 @@ |
||
46 | 46 | function find($column) |
47 | 47 | { |
48 | 48 | foreach($this->items as $item) { |
49 | - if($item->name === $column) return $item; |
|
49 | + if($item->name === $column) { |
|
50 | + return $item; |
|
51 | + } |
|
50 | 52 | } |
51 | 53 | |
52 | 54 | return null; |
@@ -21,7 +21,7 @@ |
||
21 | 21 | /** @noinspection PhpUnhandledExceptionInspection */ |
22 | 22 | public function __construct() |
23 | 23 | { |
24 | - if(!($this instanceof FormRequest)) |
|
24 | + if (!($this instanceof FormRequest)) |
|
25 | 25 | throw new BadTraitImplementation(__TRAIT__); |
26 | 26 | |
27 | 27 | // Create an instance of the validation rule |
@@ -21,8 +21,9 @@ |
||
21 | 21 | /** @noinspection PhpUnhandledExceptionInspection */ |
22 | 22 | public function __construct() |
23 | 23 | { |
24 | - if(!($this instanceof FormRequest)) |
|
25 | - throw new BadTraitImplementation(__TRAIT__); |
|
24 | + if(!($this instanceof FormRequest)) { |
|
25 | + throw new BadTraitImplementation(__TRAIT__); |
|
26 | + } |
|
26 | 27 | |
27 | 28 | // Create an instance of the validation rule |
28 | 29 | $this->sortParameterRule = new SortParameter($this->getSortableColumns()); |