Module::isEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2019 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Flange;
14
15
/**
16
 * A module extension feature (A.K.A plugin).
17
 *
18
 * @author Divine Niiquaye Ibok <[email protected]>
19
 */
20
final class Module implements \JsonSerializable, \IteratorAggregate
21
{
22
    private array $moduleConfig;
23
    private string $directory;
24
25
    public function __construct(string $directory, array $moduleConfig)
26
    {
27
        $this->directory = $directory;
28
        $this->moduleConfig = $moduleConfig;
29
    }
30
31
    /**
32
     * Checks if module is enabled or not.
33
     */
34
    public function isEnabled(): bool
35
    {
36
        return $this->moduleConfig['enabled'] ?? false;
37
    }
38
39
    /**
40
     * If the module has an author.
41
     */
42
    public function getAuthor(): ?string
43
    {
44
        return $this->moduleConfig['author'] ?? null;
45
    }
46
47
    /**
48
     * {@see Rade\Traits\HelperTrait::loadExtensions()}.
49
     */
50
    public function getExtensions(): array
51
    {
52
        return $this->moduleConfig['extensions'] ?? [];
53
    }
54
55
    /**
56
     * Gets the module's directory.
57
     */
58
    public function getDirectory(): string
59
    {
60
        return $this->directory;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     *
66
     * @return mixed
67
     */
68
    #[\ReturnTypeWillChange]
69
    public function jsonSerialize()
70
    {
71
        return $this->moduleConfig;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getIterator(): \Traversable
78
    {
79
        return new \ArrayIterator($this->moduleConfig);
80
    }
81
}
82