CallbackTranslator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 12
c 3
b 1
f 0
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A translateValueInput() 0 7 2
A __construct() 0 5 1
A translateValueOutput() 0 7 2
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\Url\Params\Translator;
8
9
/**
10
 * Translator which uses callbacks for input/output translation
11
 */
12
class CallbackTranslator extends StaticTranslator
13
{
14
    protected $valueInputTranslator;
15
    protected $valueOutputTranslator;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param string $keyName
21
     * @param string $keyTranslation
22
     * @param callable $valueInputTranslator
23
     * @param callable $valueOutputTranslator
24
     */
25 3
    public function __construct($keyName, $keyTranslation, $valueInputTranslator, $valueOutputTranslator)
26
    {
27 3
        parent::__construct($keyName, $keyTranslation, array());
28 3
        $this->valueInputTranslator  = $valueInputTranslator;
29 3
        $this->valueOutputTranslator = $valueOutputTranslator;
30 3
    }
31
32
    /**
33
     * @{inheritDoc}
34
     */
35 2
    public function translateValueInput($keyName, $value)
36
    {
37 2
        if ($this->translateKeyInput($keyName) !== false) {
0 ignored issues
show
introduced by
The condition $this->translateKeyInput($keyName) !== false is always true.
Loading history...
38 2
            return call_user_func($this->valueInputTranslator, $value);
39
        }
40
41 1
        return false;
42
    }
43
44
    /**
45
     * @{inheritDoc}
46
     */
47 2
    public function translateValueOutput($keyName, $value)
48
    {
49 2
        if ($this->translateKeyOutput($keyName) !== false) {
0 ignored issues
show
introduced by
The condition $this->translateKeyOutput($keyName) !== false is always true.
Loading history...
50 2
            return call_user_func($this->valueOutputTranslator, $value);
51
        }
52
53 1
        return false;
54
    }
55
}
56