These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\TaggingBundle\Entity; |
||
4 | |||
5 | use Doctrine\Common\Collections\ArrayCollection; |
||
6 | use Doctrine\Common\Collections\Collection; |
||
7 | use Doctrine\Common\Proxy\Proxy; |
||
8 | |||
9 | /** |
||
10 | * @method getId |
||
11 | */ |
||
12 | trait TaggableTrait |
||
13 | { |
||
14 | /** |
||
15 | * @var Collection |
||
16 | */ |
||
17 | private $tags; |
||
18 | |||
19 | /** |
||
20 | * @var \Closure |
||
21 | */ |
||
22 | private $lazyTagLoader; |
||
23 | |||
24 | /** |
||
25 | * Returns the unique taggable resource type |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | 4 | public function getTaggableType() |
|
30 | { |
||
31 | 4 | return ($this instanceof Proxy) ? get_parent_class($this) : \get_class($this); |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Returns the unique taggable resource identifier |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | 2 | public function getTaggableId() |
|
40 | { |
||
41 | 2 | return $this->getId(); |
|
0 ignored issues
–
show
|
|||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Returns the collection of tags for this Taggable entity |
||
46 | * |
||
47 | * @return \Doctrine\Common\Collections\Collection |
||
48 | */ |
||
49 | 4 | public function getTags() |
|
50 | { |
||
51 | 4 | if (null === $this->tags) { |
|
52 | 3 | $this->tags = new ArrayCollection(); |
|
53 | |||
54 | 3 | if ($this->lazyTagLoader) { |
|
55 | 1 | \call_user_func($this->lazyTagLoader, $this); |
|
56 | } |
||
57 | } |
||
58 | |||
59 | 4 | return $this->tags; |
|
60 | } |
||
61 | |||
62 | 1 | public function setTags(Collection $tags) |
|
63 | { |
||
64 | 1 | $this->tags = $tags; |
|
65 | |||
66 | 1 | return $this; |
|
67 | } |
||
68 | |||
69 | 2 | public function setTagLoader(\Closure $loader) |
|
70 | { |
||
71 | 2 | $this->lazyTagLoader = $loader; |
|
72 | 2 | } |
|
73 | } |
||
74 |
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.