ChainedMapper::main()   A
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 20
rs 9.2222
c 0
b 0
f 0
cc 6
nc 10
nop 1
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Mapper;
22
23
/**
24
 * A <code>ContainerMapper</code> that chains the results of the first
25
 * nested <code>FileNameMapper</code>s into sourcefiles for the second,
26
 * the second to the third, and so on, returning the resulting mapped
27
 * filenames from the last nested <code>FileNameMapper</code>.
28
 */
29
class ChainedMapper extends ContainerMapper
30
{
31
    /**
32
     * {@inheritDoc}.
33
     */
34
    public function main($sourceFileName)
35
    {
36
        $results[] = $sourceFileName;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$results was never initialized. Although not strictly required by PHP, it is generally a good practice to add $results = array(); before regardless.
Loading history...
37
        $mapper = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $mapper is dead and can be removed.
Loading history...
38
39
        foreach ($this->getMappers() as $mapper) {
40
            if (null !== $mapper) {
41
                $inputs = $results;
42
                $results = [];
43
44
                foreach ($inputs as $input) {
45
                    $mapped = $mapper->getImplementation()->main($input);
46
                    if (null != $mapped) {
47
                        $results = $mapped;
48
                    }
49
                }
50
            }
51
        }
52
53
        return !empty($results) ? $results : null;
54
    }
55
}
56