TaggableTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 8
c 4
b 1
f 2
lcom 2
cbo 2
dl 0
loc 39
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getModel() 0 4 1
A getModelId() 0 4 1
A setTags() 0 4 2
A getTags() 0 6 2
A getRemove() 0 4 1
A setRemove() 0 5 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Rafidion Michael
5
 * Date: 10/12/2014
6
 * Time: 14:08
7
 */
8
9
namespace Mykees\TagBundle\Traits;
10
11
12
use Doctrine\Common\Collections\ArrayCollection;
13
use Mykees\TagBundle\Util\Reflection;
14
15
trait TaggableTrait {
16
17
    public $tags;
18
    public $remove = false;
19
20
    public function getModel()
21
    {
22
        return Reflection::getClassShortName($this);
23
    }
24
25
    public function getModelId()
26
    {
27
        return $this->getId();
0 ignored issues
show
Bug introduced by
It seems like getId() must be provided by classes using this trait. How about adding it as abstract method to this trait?

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

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). 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.

Loading history...
28
    }
29
30
31
    public function setTags($tags)
32
    {
33
        $this->tags = !empty($tags) ? new ArrayCollection($tags) : null;
34
    }
35
36
    public function getTags()
37
    {
38
        $this->tags = $this->tags ?: new ArrayCollection();
39
        
40
        return $this->tags;
41
    }
42
43
    public function getRemove()
44
    {
45
        return $this->remove;
46
    }
47
48
    public function setRemove($remove)
49
    {
50
        $this->remove = $remove;
51
        return $this->remove;
52
    }
53
}
54