Passed
Push — master ( 72c793...7f699f )
by Kirill
03:22
created

AbstractEngine   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLoader() 0 7 2
A withLoader() 0 6 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Views\Engine;
13
14
use Spiral\Views\EngineInterface;
15
use Spiral\Views\Exception\EngineException;
16
use Spiral\Views\LoaderInterface;
17
18
/**
19
 * ViewEngine with ability to switch environment and loader.
20
 */
21
abstract class AbstractEngine implements EngineInterface
22
{
23
    protected const EXTENSION = '';
24
25
    /** @var string */
26
    protected $extension;
27
28
    /** @var LoaderInterface */
29
    protected $loader;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function withLoader(LoaderInterface $loader): EngineInterface
35
    {
36
        $engine = clone $this;
37
        $engine->loader = $loader->withExtension($this->extension ?? static::EXTENSION);
38
39
        return $engine;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getLoader(): LoaderInterface
46
    {
47
        if (empty($this->loader)) {
48
            throw new EngineException('No associated loader found');
49
        }
50
51
        return $this->loader;
52
    }
53
}
54