| 1 | <?php |
||
| 5 | trait WithPagination |
||
| 6 | { |
||
| 7 | protected $perPage = 20; |
||
| 8 | |||
| 9 | protected $pageName = 'page'; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @return int |
||
| 13 | */ |
||
| 14 | public function getPerPage(): int |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param int $perPage |
||
| 21 | * @return $this |
||
| 22 | */ |
||
| 23 | public function setPerPage(int $perPage) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @return string |
||
| 32 | */ |
||
| 33 | public function getPageName(): string |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $pageName |
||
| 40 | * @return $this |
||
| 41 | */ |
||
| 42 | public function setPageName(string $pageName) |
||
| 48 | |||
| 49 | public function paginate() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return $this |
||
| 58 | */ |
||
| 59 | public function disablePagination() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | public function isPagination() |
||
| 71 | } |
||
| 72 |
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
Idableprovides a methodequalsIdthat 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.