Completed
Pull Request — master (#70)
by Martin
03:15
created

BaseTwitalLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
namespace Goetas\Twital;
3
4
use Twig\Loader\ExistsLoaderInterface;
5
use Twig\Loader\LoaderInterface;
6
use Twig\Loader\SourceContextLoaderInterface;
7
use Twig\Source;
8
9
abstract class BaseTwitalTwigLt3Loader
10
{
11
    use TwitalLoaderTrait;
12
13
    public function __construct($loader = null, Twital $twital = null, $addDefaults = true)
14
    {
15
        $this->doConstruct($loader, $twital, $addDefaults);
16
    }
17
18
    public function getCacheKey($name)
19
    {
20
        return $this->loader->getCacheKey($name);
21
    }
22
23
    public function isFresh($name, $time)
24
    {
25
        return $this->loader->isFresh($name, $time);
26
    }
27
28
    public function getSourceContext($name)
29
    {
30
        $context = $this->doGetSourceContext($name);
31
32
        return new \Twig_Source($context[0], $context[1], $context[2]);
33
    }
34
35
    public function exists($name)
36
    {
37
        return $this->doExists($name);
38
    }
39
}
40
41
if (interface_exists(\Twig_ExistsLoaderInterface::class)) { // Twig 1
42
    abstract class BaseTwitalLoader extends BaseTwitalTwigLt3Loader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface
43
    {
44 48
        public function __construct(\Twig_LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
45
        {
46 48
            parent::__construct($loader, $twital, $addDefaults);
47 48
        }
48
49 48
        /**
50 6
         * {@inheritdoc}
51 6
         */
52 48
        public function getSource($name)
53 6
        {
54 6
            return $this->getSourceContext($name)->getCode();
55 48
        }
56 6
    }
57 6
} elseif (interface_exists(ExistsLoaderInterface::class)) { // Twig 2
58 48
    abstract class BaseTwitalLoader extends BaseTwitalTwigLt3Loader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Goetas\Twital\BaseTwitalLoader has been defined more than once; this definition is ignored, only the first definition in this file (L42-56) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
59
    {
60 31
        public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
61
        {
62 31
            parent::__construct($loader, $twital, $addDefaults);
63 29
        }
64 29
    }
65 29
} else { // Twig 3
66 29
    abstract class BaseTwitalLoader implements LoaderInterface
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Goetas\Twital\BaseTwitalLoader has been defined more than once; this definition is ignored, only the first definition in this file (L42-56) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
67 2
    {
68 1
        use TwitalLoaderTrait;
69
70
        public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
71 30
        {
72 28
            $this->doConstruct($loader, $twital, $addDefaults);
73 26
        }
74
75 28
        public function getSourceContext(string $name): Source
76
        {
77
            $context = $this->doGetSourceContext($name);
78
79
            return new Source($context[0], $context[1], $context[2]);
80
        }
81
82
        public function getCacheKey(string $name): string
83
        {
84
            return $this->loader->getCacheKey($name);
85
        }
86
87 46
        public function isFresh(string $name, int $time): bool
88
        {
89 46
            return $this->loader->isFresh($name, $time);
90
        }
91 46
92
        public function exists(string $name)
93
        {
94
            return $this->doExists($name);
95
        }
96
    }
97
}
98
99 1
/**
100
 * This is a Twital Loader.
101 1
 * Compiles a Twital template into a Twig template.
102
 *
103
 * @author Asmir Mustafic <[email protected]>
104
 */
105
class TwitalLoader extends BaseTwitalLoader
106
{
107
}
108