Completed
Pull Request — master (#70)
by Martin
02:59
created

TwitalLoader::addSourceAdapter()   A

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
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
if (interface_exists(\Twig_ExistsLoaderInterface::class)) { // Twig 1
10
    abstract class BaseTwitalLoader extends TwitalLoaderTwigLt3 implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface
11
    {
12
        public function __construct(\Twig_LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
13
        {
14
            parent::__construct($loader, $twital, $addDefaults);
15
        }
16
17
        public function getSourceContext($name)
18
        {
19
            $context = $this->doGetSourceContext($name);
20
21
            return new \Twig_Source($context[0], $context[1], $context[2]);
22
        }
23
24
        /**
25
         * {@inheritdoc}
26
         */
27
        public function getSource($name)
28
        {
29
            return $this->getSourceContext($name)->getCode();
30
        }
31
    }
32
} elseif (interface_exists(ExistsLoaderInterface::class)) { // Twig 2
33
    abstract class BaseTwitalLoader extends TwitalLoaderTwigLt3 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 (L10-31) 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...
34
    {
35
        public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
36
        {
37
            parent::__construct($loader, $twital, $addDefaults);
38
        }
39
40
        public function getSourceContext($name)
41
        {
42
            $context = $this->doGetSourceContext($name);
43
44 48
            return new Source($context[0], $context[1], $context[2]);
45
        }
46 48
    }
47 48
} else { // Twig 3
48
    abstract class BaseTwitalLoader extends TwitalLoaderTwigGte3
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 (L10-31) 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...
49 48
    {
50 6
    }
51 6
}
52 48
53 6
/**
54 6
 * This is a Twital Loader.
55 48
 * Compiles a Twital template into a Twig template.
56 6
 *
57 6
 * @author Asmir Mustafic <[email protected]>
58 48
 */
59
class TwitalLoader extends BaseTwitalLoader
60 31
{
61
}
62