1 | <?php |
||
40 | trait YEMAwareTrait |
||
41 | { |
||
42 | /** |
||
43 | * @return MediatorInterface |
||
44 | * @throws \LogicException |
||
45 | */ |
||
46 | 30 | public function getYem(): MediatorInterface |
|
47 | { |
||
48 | 30 | if (null === $this->yem) { |
|
49 | $parent = get_parent_class($this); |
||
50 | if ($parent instanceof YEMAwareInterface) { |
||
51 | $this->yem = $parent->getYem(); |
||
52 | } elseif (method_exists($this, 'getDic')) { |
||
53 | $this->yem = $this->getDic()['Yapeal.Event.Callable.Mediator']; |
||
|
|||
54 | } else { |
||
55 | $mess = 'Tried to use yem before it was set'; |
||
56 | throw new \LogicException($mess); |
||
57 | } |
||
58 | } |
||
59 | 30 | return $this->yem; |
|
60 | } |
||
61 | /** |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function hasYem(): bool |
||
68 | /** |
||
69 | * @param MediatorInterface $value |
||
70 | * |
||
71 | * @return static Fluent interface. |
||
72 | */ |
||
73 | 36 | public function setYem(MediatorInterface $value) |
|
78 | /** |
||
79 | * @var MediatorInterface $yem |
||
80 | */ |
||
81 | private $yem; |
||
82 | } |
||
83 |
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.