Completed
Pull Request — master (#44)
by Cees-Jan
20:58 queued 19:07
created

LoaderEvent::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1.0156
1
<?php
2
3
/**
4
 * This file is part of TwigView.
5
 *
6
 ** (c) 2015 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\TwigView\Event;
12
13
use Cake\Event\Event;
14
15
class LoaderEvent extends Event
16
{
17
    const EVENT = 'TwigView.TwigView.loader';
18
19
    /**
20
     * @param \Twig_LoaderInterface $loader
21
     * @return LoaderEvent
22
     */
23 13
    public static function create(\Twig_LoaderInterface $loader)
24
    {
25 13
        return new static(static::EVENT, $loader, [
26
            'loader' => $loader,
27
        ]);
28 13
    }
29
30
    /**
31
     * @return \Twig_LoaderInterface
32
     */
33
    public function getLoader()
34
    {
35
        return $this->subject();
36
    }
37
38
    /**
39
     * @return string|Twig_LoaderInterface
40
     */
41 13
    public function getResultLoader()
42
    {
43 13
        if ($this->result instanceof \Twig_LoaderInterface) {
44 1
            return $this->result;
45
        }
46
47
        if (is_array($this->result) && $this->result['loader'] instanceof \Twig_LoaderInterface) {
48 1
            return $this->result['loader'];
49
        }
50
51
        return $this->getLoader();
52
    }
53
}
54