Passed
Push — master ( f0f3e0...43398f )
by Angel Fernando Quiroz
08:45 queued 14s
created

PluginRepository::enablePlugin()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\Plugin;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Persistence\ManagerRegistry;
12
13
/**
14
 * @extends ServiceEntityRepository<Plugin>
15
 * @method Plugin|null findOneByTitle(string $title)
16
 */
17
class PluginRepository extends ServiceEntityRepository
18
{
19
    public function __construct(ManagerRegistry $registry)
20
    {
21
        parent::__construct($registry, Plugin::class);
22
    }
23
24
    /**
25
     * Get all installed plugins.
26
     *
27
     * @return array<int, Plugin>
28
     */
29
    public function getInstalledPlugins(): array
30
    {
31
        return $this->findBy(['installed' => true]);
32
    }
33
34
    /**
35
     * Get all active plugins.
36
     *
37
     * @return array<int, Plugin>
38
     */
39
    public function getActivePlugins(): array
40
    {
41
        return $this->findBy(['installed' => true, 'active' => true]);
42
    }
43
44
    /**
45
     * Check if a plugin is installed.
46
     */
47
    public function isInstalledByName(string $pluginName): bool
48
    {
49
        return null !== $this->findOneBy(['title' => $pluginName, 'installed' => true]);
50
    }
51
52
    /**
53
     * Check if a plugin is active.
54
     */
55
    public function isActiveByName(string $pluginName): bool
56
    {
57
        $plugin = $this->findOneBy(['title' => $pluginName, 'installed' => true]);
58
59
        return $plugin ? $plugin->isActive() : false;
60
    }
61
}
62