CallbackTranslator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 4
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
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