TwigFilterExtension::yesnoiconFilter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
namespace Vivait\BootstrapBundle\Twig;
3
4
use \Twig_Filter_Function;
5
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
6
7
class TwigFilterExtension extends \Twig_Extension {
8
    public function getName() {
9
        return 'twig_extension';
10
    }
11
12
	
13
    public function getFilters() {
14
        return array(
15
			new \Twig_SimpleFilter('yesno', array($this, 'yesnoFilter')),
16
			new \Twig_SimpleFilter('yesnoicon', array($this, 'yesnoiconFilter')),
17
			new \Twig_SimpleFilter('gender', array($this, 'genderFilter')),
18
			new \Twig_SimpleFilter('money', array($this, 'moneyFilter')),
19
			new \Twig_SimpleFilter('printr', array($this, 'printrFilter')),
20
			new \Twig_SimpleFilter('file_exists', array($this, 'file_exists'))
21
        );
22
    }
23
	
24
	public function yesnoFilter($boolean) {
25
		return $boolean?'Yes':'No';
26
	}
27
	
28
	public function yesnoiconFilter($boolean) {
29
		return $boolean?'<i class="text-success glyphicon glyphicon-ok"></i>':'<i class="text-danger glyphicon glyphicon-remove"></i>';
30
	}
31
	
32
	public function genderFilter($sex) {
33
		if($sex=='M') {
34
			return 'Male';
35
		} elseif($sex=='F') {
36
			return 'Female';
37
		} else {
38
			return 'Unknown';
39
		}
40
	}
41
42
	public function moneyFilter($float,$currency = NULL) {
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...
43
		$nf = new NumberFormatter('en', NumberFormatter::CURRENCY);
44
		if($currency) {
45
			return $nf->formatCurrency($float,$currency);
46
		} else {
47
			return number_format($float,2,'.',',');
48
		}
49
50
51
	}
52
53
	public function file_exists($file) {
54
		return file_exists($file);
55
	}
56
	
57
}
58
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
59