Passed
Push — master ( 888f66...5c6945 )
by Angel Fernando Quiroz
08:42 queued 14s
created

PluginRepository::getInstalledByName()   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 1
dl 0
loc 3
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
     * Get an installed plugin.
46
     */
47
    public function getInstalledByName(string $pluginName): ?Plugin
48
    {
49
        return $this->findOneBy(['title' => $pluginName, 'installed' => true]);
50
    }
51
52
    /**
53
     * Check if a plugin is installed.
54
     */
55
    public function isInstalledByName(string $pluginName): bool
56
    {
57
        return null !== $this->getInstalledByName($pluginName);
58
    }
59
60
    /**
61
     * Check if a plugin is active.
62
     */
63
    public function isActiveByName(string $pluginName): bool
64
    {
65
        $plugin = $this->findOneBy(['title' => $pluginName, 'installed' => true]);
66
67
        return $plugin ? $plugin->isActive() : false;
68
    }
69
}
70