FormatingExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFilters() 0 7 1
A textify() 0 4 1
A rule() 0 4 1
A getName() 0 4 1
1
<?php
2
namespace Hal\Application\Formater\Twig;
3
4
use Hal\Application\Rule\Validator;
5
6
class FormatingExtension extends \Twig_Extension
7
{
8
    /**
9
     * @var Validator
10
     */
11
    private $validator;
12
13
    /**
14
     * Validator
15
     *
16
     * @param Validator $validator
17
     */
18
    function __construct(Validator $validator)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
    {
20
        $this->validator = $validator;
21
    }
22
23
    /**
24
     * @inherit
25
     */
26
    public function getFilters()
27
    {
28
        return array(
29
            new \Twig_SimpleFilter('textify', array($this, 'textify'))
30
            , new \Twig_SimpleFilter('rule', array($this, 'rule'))
31
        );
32
    }
33
34
    /**
35
     * String as readable text
36
     *
37
     * @param $v
38
     * @return string
39
     */
40
    public function textify($v)
41
    {
42
        return ucfirst(preg_replace( '/([a-z0-9])([A-Z])/', "$1 $2", $v ));
43
    }
44
45
    /**
46
     * Check value according rule
47
     *
48
     * @param $key
49
     * @param $v
50
     * @return string
51
     */
52
    public function rule($v, $key)
53
    {
54
        return $this->validator->validate($key, $v);
55
    }
56
57
    /**
58
     * @inherit
59
     */
60
    public function getName()
61
    {
62
        return 'hal_formating_extension';
63
    }
64
}
65