Completed
Push — master ( 5d51b4...87fdd9 )
by Paul
10s
created

SpaceShip::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Acme\AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
7
use Symfony\Component\PropertyAccess\PropertyAccess;
8
use Victoire\Bundle\BusinessEntityBundle\Entity\Traits\BusinessEntityTrait;
9
use Victoire\Bundle\CoreBundle\Annotations as VIC;
10
11
/**
12
 * Mercenary.
13
 *
14
 * @ORM\Entity
15
 * @ORM\Table("space_ship")
16
 * @VIC\BusinessEntity({"Force"})
17
 */
18
class SpaceShip
19
{
20
    use BusinessEntityTrait;
21
    use Translatable;
22
23
    /**
24
     * @var int
25
     *
26
     * @ORM\Column(name="id", type="integer")
27
     * @ORM\Id
28
     * @ORM\GeneratedValue(strategy="AUTO")
29
     */
30
    private $id;
31
32
    /**
33
     * @return int
34
     */
35
    public function getId()
36
    {
37
        return $this->id;
38
    }
39
40
    public function __toString()
41
    {
42
        return $this->getName();
43
    }
44
45
    public function getName()
46
    {
47
        return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getName');
48
    }
49
50
    public function setName($name, $locale = null)
51
    {
52
        $this->translate($locale, false)->setDescription($name);
0 ignored issues
show
Bug introduced by
It seems like setDescription() 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...
53
        $this->mergeNewTranslations();
54
    }
55
56
    public function getSlug()
57
    {
58
        return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), 'getSlug');
59
    }
60
61
    public function setSlug($slug, $locale = null)
62
    {
63
        $this->translate($locale, false)->setDescription($slug);
0 ignored issues
show
Bug introduced by
It seems like setDescription() 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...
64
        $this->mergeNewTranslations();
65
    }
66
}
67