Passed
Pull Request — master (#6127)
by Angel Fernando Quiroz
08:00
created

Plugin::addUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
13
#[ORM\Entity]
14
#[ORM\Table(name: 'plugin')]
15
class Plugin
16
{
17
    public const SOURCE_THIRD_PARTY = 'third_party';
18
    public const SOURCE_OFFICIAL = 'official';
19
20
    #[ORM\Id]
21
    #[ORM\GeneratedValue]
22
    #[ORM\Column(type: 'integer')]
23
    private ?int $id = null;
24
25
    #[ORM\Column(type: 'string', length: 255, unique: true)]
26
    private string $title;
27
28
    #[ORM\Column(type: 'boolean')]
29
    private bool $installed = false;
30
31
    #[ORM\Column(type: 'string', length: 20)]
32
    private string $installedVersion;
33
34
    #[ORM\Column(type: 'string', length: 20, options: ['default' => self::SOURCE_THIRD_PARTY])]
35
    private string $source = 'third_party';
36
37
    /**
38
     * @var Collection<int, AccessUrlRelPlugin>
39
     */
40
    #[ORM\OneToMany(mappedBy: 'plugin', targetEntity: AccessUrlRelPlugin::class, orphanRemoval: true)]
41
    private Collection $urls;
42
43
    public function __construct()
44
    {
45
        $this->urls = new ArrayCollection();
46
    }
47
48
    public function getId(): ?int
49
    {
50
        return $this->id;
51
    }
52
53
    public function getTitle(): string
54
    {
55
        return $this->title;
56
    }
57
58
    public function setTitle(string $title): self
59
    {
60
        $this->title = $title;
61
62
        return $this;
63
    }
64
65
    public function isInstalled(): bool
66
    {
67
        return $this->installed;
68
    }
69
70
    public function setInstalled(bool $installed): self
71
    {
72
        $this->installed = $installed;
73
74
        return $this;
75
    }
76
77
    public function getInstalledVersion(): string
78
    {
79
        return $this->installedVersion;
80
    }
81
82
    public function setInstalledVersion(string $installedVersion): self
83
    {
84
        $this->installedVersion = $installedVersion;
85
86
        return $this;
87
    }
88
89
    public function getSource(): string
90
    {
91
        return $this->source;
92
    }
93
94
    public function setSource(string $source): self
95
    {
96
        $this->source = $source;
97
98
        return $this;
99
    }
100
101
    /**
102
     * @return Collection<int, AccessUrlRelPlugin>
103
     */
104
    public function getUrls(): Collection
105
    {
106
        return $this->urls;
107
    }
108
109
    public function addUrl(AccessUrlRelPlugin $url): static
110
    {
111
        if (!$this->urls->contains($url)) {
112
            $this->urls->add($url);
113
            $url->setPlugin($this);
114
        }
115
116
        return $this;
117
    }
118
119
    public function removeUrl(AccessUrlRelPlugin $url): static
120
    {
121
        if ($this->urls->removeElement($url)) {
122
            // set the owning side to null (unless already changed)
123
            if ($url->getPlugin() === $this) {
124
                $url->setPlugin(null);
125
            }
126
        }
127
128
        return $this;
129
    }
130
}
131