Completed
Push — master ( 84255c...a7d7e4 )
by Thomas
14:38
created

TwigTrait::getRawTwig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
rs 9.2
ccs 0
cts 16
cp 0
cc 2
eloc 8
nc 2
nop 1
crap 6
1
<?php
2
namespace keeko\core\utils;
3
4
use keeko\core\service\ServiceContainer;
5
6
trait TwigTrait {
7
	
8
	private $twig;
9
	
10
	/**
11
	 * @return ServiceContainer
12
	 */
13
	abstract public function getServiceContainer();
14
15
	protected function getRawTwig($templatePath) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
16
		if ($this->twig === null) {
17
			$loader = new \Twig_Loader_Filesystem($templatePath);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
18
			$this->twig = new \Twig_Environment($loader);
19
			
20
// 			$translator = $this->getServiceContainer()->getTranslator();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
			
22
// 			// translator function
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
// 			$trans = function($key, $params = [], $domain = null) use ($translator) {
24
// 				return $translator->trans($key, $params, $domain);
25
// 			};
26
// 			$this->twig->addFunction(new \Twig_SimpleFunction('t', $trans));
27
28
			// firewall
29
			$firewall = $this->getServiceContainer()->getFirewall();
30
			$this->twig->addFunction(new \Twig_SimpleFunction('hasPermission', function ($module, $action) use ($firewall) {
31
				return $firewall->hasPermission($module, $action);
32
			}));
33
		}
34
		
35
		return $this->twig;
36
	}
37
}