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

LoaderEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
ccs 7
cts 9
cp 0.7778
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 1
A getLoader() 0 4 1
A getResultLoader() 0 12 4
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