1 | <?php |
||
27 | trait MutualTrait |
||
28 | { |
||
29 | |||
30 | public $otherGuidAttribute = 'other_guid'; |
||
31 | |||
32 | /** |
||
33 | * Get initiator. |
||
34 | * @return BaseUserQuery |
||
35 | */ |
||
36 | 1 | public function getInitiator() |
|
37 | { |
||
38 | 1 | return $this->getUser(); |
|
|
|||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get recipient. |
||
43 | * @return BaseUserQuery |
||
44 | */ |
||
45 | 1 | public function getRecipient() |
|
46 | { |
||
47 | 1 | if (!is_string($this->otherGuidAttribute)) { |
|
48 | return null; |
||
49 | } |
||
50 | 1 | $userClass = $this->userClass; |
|
51 | 1 | $model = $userClass::buildNoInitModel(); |
|
52 | 1 | return $this->hasOne($userClass::className(), [$model->guidAttribute => $this->otherGuidAttribute]); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Set recipient. |
||
57 | * @param BaseUserModel $user |
||
58 | * @return string |
||
59 | */ |
||
60 | public function setRecipient($user) |
||
68 | |||
69 | /** |
||
70 | * Get mutual attributes rules. |
||
71 | * @return array |
||
72 | */ |
||
73 | 15 | public function getMutualRules() |
|
84 | } |
||
85 |
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.