CompositeTranslator::translateValueInput()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
/**
4
 * @author Gerard van Helden <[email protected]>
5
 * @copyright Zicht Online <http://zicht.nl>
6
 */
7
8
namespace Zicht\Bundle\UrlBundle\Url\Params\Translator;
9
10
use Zicht\Bundle\UrlBundle\Url\Params\Translator;
11
12
/**
13
 * Composite translator which delegates to the translator that translates a key.
14
 */
15
class CompositeTranslator implements Translator
16
{
17
    protected $translators = array();
18
19
    /**
20
     * @{inheritDoc}
21
     */
22 2
    public function translateKeyInput($keyName)
23
    {
24 2
        foreach ($this->translators as $translator) {
25 2
            if (false !== ($translation = $translator->translateKeyInput($keyName))) {
26 2
                return $translation;
27
            }
28
        }
29
30 1
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by Zicht\Bundle\UrlBundle\U...or::translateKeyInput() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
31
    }
32
33
34
    /**
35
     * @{inheritDoc}
36
     */
37 1
    public function translateValueInput($keyName, $value)
38
    {
39 1
        foreach ($this->translators as $translator) {
40 1
            if (false !== ($translation = $translator->translateValueInput($keyName, $value))) {
41 1
                return $translation;
42
            }
43
        }
44
45 1
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by Zicht\Bundle\UrlBundle\U...::translateValueInput() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
46
    }
47
48
49
    /**
50
     * @{inheritDoc}
51
     */
52 2
    public function translateKeyOutput($keyName)
53
    {
54 2
        foreach ($this->translators as $translator) {
55 2
            if (false !== ($translation = $translator->translateKeyOutput($keyName))) {
56 2
                return $translation;
57
            }
58
        }
59
60 1
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by Zicht\Bundle\UrlBundle\U...r::translateKeyOutput() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
61
    }
62
63
64
    /**
65
     * @{inheritDoc}
66
     */
67 1
    public function translateValueOutput($keyName, $value)
68
    {
69 1
        foreach ($this->translators as $translator) {
70 1
            if (false !== ($translation = $translator->translateValueOutput($keyName, $value))) {
71 1
                return $translation;
72
            }
73
        }
74
75 1
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by Zicht\Bundle\UrlBundle\U...:translateValueOutput() of string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
76
    }
77
78
79
    /**
80
     * @{inheritDoc}
81
     */
82 2
    public function add(Translator $translator)
83
    {
84 2
        $this->translators[] = $translator;
85
86 2
        return $this;
87
    }
88
}
89