1 | <?php |
||
16 | trait Api |
||
17 | { |
||
18 | /** @var mixed */ |
||
19 | protected $api; |
||
20 | |||
21 | /** |
||
22 | * Get api |
||
23 | * |
||
24 | * @return AbstractApi|AbstractActivity|AbstractEnterprise|AbstractGists|AbstractGitData|AbstractIssues|AbstractMiscellaneous|AbstractOrganizations|AbstractPullRequests|AbstractRepositories |
||
25 | */ |
||
26 | public function getApi() |
||
30 | |||
31 | /** |
||
32 | * Set api |
||
33 | * |
||
34 | * @param AbstractApi|AbstractActivity|AbstractEnterprise|AbstractGists|AbstractGitData|AbstractIssues|AbstractMiscellaneous|AbstractOrganizations|AbstractPullRequests|AbstractRepositories $api |
||
35 | * |
||
36 | * @return Api |
||
|
|||
37 | */ |
||
38 | public function setApi($api): self |
||
44 | } |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.