1 | <?php |
||
5 | trait CommonHelper |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * @param $page |
||
10 | * @param $perPage |
||
11 | * @param null $numRows |
||
12 | * |
||
13 | * @return array |
||
14 | */ |
||
15 | protected function getPaginationLinks($page, $perPage, $numRows = null) :array |
||
25 | |||
26 | /** |
||
27 | * @param $page |
||
28 | * @param $limit |
||
29 | * @param $uri |
||
30 | * @param $links |
||
31 | * |
||
32 | * @return array |
||
33 | */ |
||
34 | protected function getPaginationViewData($page, $limit, $uri, &$links) :array |
||
43 | |||
44 | /** |
||
45 | * @param array $result |
||
46 | * @param string $type |
||
47 | */ |
||
48 | protected function validationErrors(array $result, string $type = 'alert') :void |
||
61 | |||
62 | /** |
||
63 | * @param $slug |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function getIdFromSlug(string $slug) :string |
||
73 | |||
74 | /** |
||
75 | * @param string $uri |
||
76 | * |
||
77 | * @return mixed |
||
78 | */ |
||
79 | protected function redirectToSelf(string $uri) |
||
89 | |||
90 | /** |
||
91 | * @param $array |
||
92 | * @param $arrayKey |
||
93 | * |
||
94 | * @return int|string |
||
95 | */ |
||
96 | protected function searchArrayKey($array, $arrayKey) |
||
104 | |||
105 | /** |
||
106 | * @param $value |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | protected function dateFormat($value) |
||
117 | |||
118 | /** |
||
119 | * @param $value |
||
120 | * |
||
121 | * @return int |
||
122 | */ |
||
123 | protected function checkbox($value) |
||
127 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.