Module   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 60
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtensions() 0 3 1
A jsonSerialize() 0 4 1
A getIterator() 0 3 1
A isEnabled() 0 3 1
A getDirectory() 0 3 1
A getAuthor() 0 3 1
A __construct() 0 4 1
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