| 1 | <?php |
||
| 8 | trait ManagesProjects |
||
| 9 | { |
||
| 10 | use TransformsProjects; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Get a list of of projects. |
||
| 14 | * |
||
| 15 | * @param int $accountId |
||
| 16 | * @return Project[] |
||
| 17 | */ |
||
| 18 | 7 | public function projects(int $accountId): array |
|
| 19 | { |
||
| 20 | 7 | $result = $this->get("{$accountId}/internal-projects"); |
|
|
|
|||
| 21 | |||
| 22 | return array_map(function ($project) { |
||
| 23 | 1 | return $this->fromDoneDoneProject($project); |
|
| 24 | 1 | }, is_array($result) ? $result : []); |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Get a single project. |
||
| 29 | * |
||
| 30 | * @param int $accountId |
||
| 31 | * @param int $id |
||
| 32 | * |
||
| 33 | * @return Project |
||
| 34 | */ |
||
| 35 | 1 | public function project(int $accountId, int $id): Project |
|
| 41 | } |
||
| 42 |
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.