LoaderEvent::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of TwigView.
6
 *
7
 ** (c) 2015 Cees-Jan Kiewiet
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 WyriHaximus\TwigView\Event;
14
15
use Cake\Event\Event;
16
use Twig\Loader\LoaderInterface;
17
18
final class LoaderEvent extends Event
19
{
20
    public const EVENT = 'TwigView.TwigView.loader';
21
22
    /**
23
     * @param  \Twig\Loader\LoaderInterface $loader
24
     * @return static
25
     */
26 20
    public static function create(LoaderInterface $loader): LoaderEvent
27
    {
28 20
        return new static(static::EVENT, $loader, [
29 20
            'loader' => $loader,
30
        ]);
31
    }
32
33
    /**
34
     * @return \Twig\Loader\LoaderInterface
35
     */
36 18
    public function getLoader(): LoaderInterface
37
    {
38 18
        return $this->getSubject();
39
    }
40
41
    /**
42
     * @return string|\WyriHaximus\TwigView\Event\Twig\Loader\LoaderInterface
43
     */
44 20
    public function getResultLoader(): LoaderInterface
45
    {
46 20
        if ($this->result instanceof LoaderInterface) {
47 1
            return $this->result;
48
        }
49
50 19
        if (is_array($this->result) && $this->result['loader'] instanceof LoaderInterface) {
51 1
            return $this->result['loader'];
52
        }
53
54 18
        return $this->getLoader();
55
    }
56
}
57