| Total Complexity | 5 | 
| Total Lines | 52 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 9 | trait SortsViaRequest | ||
| 10 | { | ||
| 11 | /** | ||
| 12 | * Returns the columns that can be sorted on. | ||
| 13 | * | ||
| 14 | * @return array | ||
| 15 | */ | ||
| 16 | abstract function getSortableColumns(): array; | ||
|  | |||
| 17 | |||
| 18 | /** @var SortParameter $sortParameterRule */ | ||
| 19 | private $sortParameterRule; | ||
| 20 | |||
| 21 | /** @noinspection PhpUnhandledExceptionInspection */ | ||
| 22 | public function __construct() | ||
| 23 |     { | ||
| 24 | if(!($this instanceof FormRequest)) | ||
| 25 | throw new BadTraitImplementation(__TRAIT__); | ||
| 26 | |||
| 27 | // Create an instance of the validation rule | ||
| 28 | $this->sortParameterRule = new SortParameter($this->getSortableColumns()); | ||
| 29 | } | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Returns the validated sorting rules. | ||
| 33 | * | ||
| 34 | * @return array | ||
| 35 | */ | ||
| 36 | function validatedSortingRules() | ||
| 37 |     { | ||
| 38 | return $this->sortParameterRule->sortingRules; | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Returns the transformed sortable columns. | ||
| 43 | * | ||
| 44 | * @return \musa11971\SortRequest\SortableColumnCollection | ||
| 45 | */ | ||
| 46 | function transformedSortableColumns() | ||
| 47 |     { | ||
| 48 | return $this->sortParameterRule->sortableColumns; | ||
| 49 | } | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Get the validation rules for the sorting. | ||
| 53 | * | ||
| 54 | * @param string $parameterName | ||
| 55 | * @return array | ||
| 56 | */ | ||
| 57 | protected function sortingRules($parameterName = 'sort') | ||
| 61 | ]; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | 
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.