Passed
Pull Request — release/4.x (#44)
by Erik
07:43 queued 03:55
created

CompositeTranslator   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 72
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A translateValueOutput() 0 9 3
A translateKeyInput() 0 9 3
A translateKeyOutput() 0 9 3
A translateValueInput() 0 9 3
A add() 0 5 1
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 = [];
18
19
    /**
20
     * @{inheritDoc}
21
     */
22
    public function translateKeyInput($keyName)
23
    {
24
        foreach ($this->translators as $translator) {
25
            if (false !== ($translation = $translator->translateKeyInput($keyName))) {
26
                return $translation;
27
            }
28
        }
29
30
        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
    public function translateValueInput($keyName, $value)
38
    {
39
        foreach ($this->translators as $translator) {
40
            if (false !== ($translation = $translator->translateValueInput($keyName, $value))) {
41
                return $translation;
42
            }
43
        }
44
45
        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
    public function translateKeyOutput($keyName)
53
    {
54
        foreach ($this->translators as $translator) {
55
            if (false !== ($translation = $translator->translateKeyOutput($keyName))) {
56
                return $translation;
57
            }
58
        }
59
60
        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
    public function translateValueOutput($keyName, $value)
68
    {
69
        foreach ($this->translators as $translator) {
70
            if (false !== ($translation = $translator->translateValueOutput($keyName, $value))) {
71
                return $translation;
72
            }
73
        }
74
75
        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
    public function add(Translator $translator)
83
    {
84
        $this->translators[] = $translator;
85
86
        return $this;
87
    }
88
}
89