Passed
Push — master ( 95ec9a...864242 )
by Divine Niiquaye
02:52
created

ArrayStorage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 7
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addLocation() 0 3 1
A __construct() 0 3 1
A load() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Biurad opensource projects.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Biurad\UI\Storage;
19
20
use Biurad\UI\Exceptions\LoaderException;
21
use Biurad\UI\Interfaces\StorageInterface;
22
23
/**
24
 * Load templates from an array.
25
 *
26
 * @author Divine Niiquaye Ibok <[email protected]>
27
 */
28
class ArrayStorage implements StorageInterface
29
{
30
    /** @var string[] */
31
    protected $templates = [];
32
33
    /**
34
     * @param string[] $templates An array of templates
35
     */
36
    public function __construct(array $templates = [])
37
    {
38
        $this->templates = $templates;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function addLocation(string $location): void
45
    {
46
        throw new LoaderException(\sprintf('Cannot use [%s] for views loading', $location));
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function load(string $template): ?string
53
    {
54
        return $this->templates[$template] ?? null;
55
    }
56
}
57