Passed
Pull Request — master (#6127)
by Angel Fernando Quiroz
40:13 queued 28:46
created

Plugin::getSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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