Passed
Push — master ( 727abb...ceefce )
by Yannick
07:55 queued 14s
created

CShortcut   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 6 1
A getType() 0 3 1
A getTool() 0 3 1
A getResourceIdentifier() 0 3 1
A getResourceName() 0 3 1
A __toString() 0 3 1
A setShortCutNode() 0 5 1
A getId() 0 3 1
A setResourceName() 0 3 1
A getShortCutNode() 0 3 1
A setTitle() 0 5 1
A getTitle() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\ResourceNode;
12
use Chamilo\CourseBundle\Repository\CShortcutRepository;
13
use Doctrine\ORM\Mapping as ORM;
14
use Stringable;
15
use Symfony\Component\Serializer\Annotation\Groups;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
#[ORM\Table(name: 'c_shortcut')]
19
#[ORM\Entity(repositoryClass: CShortcutRepository::class)]
20
class CShortcut extends AbstractResource implements ResourceInterface, Stringable
21
{
22
    #[ORM\Column(name: 'id', type: 'integer')]
23
    #[ORM\Id]
24
    #[ORM\GeneratedValue]
25
    protected ?int $id = null;
26
27
    #[Assert\NotBlank]
28
    #[Groups(['cshortcut:read'])]
29
    #[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)]
30
    protected string $title;
31
32
    #[ORM\OneToOne(targetEntity: ResourceNode::class, inversedBy: 'shortCut')]
33
    #[ORM\JoinColumn(name: 'shortcut_node_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
34
    protected ResourceNode $shortCutNode;
35
36
    #[Groups(['cshortcut:read'])]
37
    protected string $url;
38
39
    #[Groups(['cshortcut:read'])]
40
    protected string $tool;
41
42
    #[Groups(['cshortcut:read'])]
43
    protected string $type;
44
45
    public function __toString(): string
46
    {
47
        return $this->getTitle();
48
    }
49
50
    public function getTitle(): string
51
    {
52
        return $this->title;
53
    }
54
55
    public function getUrl(): string
56
    {
57
        return '/r/'.$this->getShortCutNode()->getResourceType()->getTool()->getTitle().
58
            '/'.$this->getShortCutNode()->getResourceType()->getTitle().
59
            '/'.$this->getShortCutNode()->getId().
60
            '/link';
61
    }
62
63
    public function getTool(): string
64
    {
65
        return $this->getShortCutNode()->getResourceType()->getTool()->getTitle();
66
    }
67
68
    public function getType(): string
69
    {
70
        return $this->getShortCutNode()->getResourceType()->getTitle();
71
    }
72
73
    public function setTitle(string $title): self
74
    {
75
        $this->title = $title;
76
77
        return $this;
78
    }
79
80
    public function getResourceIdentifier(): int
81
    {
82
        return $this->id;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->id could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
83
    }
84
85
    public function getShortCutNode(): ResourceNode
86
    {
87
        return $this->shortCutNode;
88
    }
89
90
    public function setShortCutNode(ResourceNode $shortCutNode): self
91
    {
92
        $this->shortCutNode = $shortCutNode;
93
94
        return $this;
95
    }
96
97
    public function getId(): int
98
    {
99
        return $this->id;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->id could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
100
    }
101
102
    public function getResourceName(): string
103
    {
104
        return $this->getTitle();
105
    }
106
107
    public function setResourceName(string $name): self
108
    {
109
        return $this->setTitle($name);
110
    }
111
}
112