CrapMethodMerger::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
4
namespace TheCodingMachine\WashingMachine\Clover;
5
6
/**
7
 * Merges crap methods from Clover and Crap4J
8
 */
9
class CrapMethodMerger implements CrapMethodFetcherInterface
10
{
11
    /**
12
     * @var CrapMethodFetcherInterface
13
     */
14
    private $file1;
15
    /**
16
     * @var CrapMethodFetcherInterface
17
     */
18
    private $file2;
19
20
    /**
21
     * Merges methods from file 2 into methods from file 1
22
     *
23
     * @param CrapMethodFetcherInterface $file1
24
     * @param CrapMethodFetcherInterface $file2
25
     */
26
    public function __construct(CrapMethodFetcherInterface $file1, CrapMethodFetcherInterface $file2)
27
    {
28
29
        $this->file1 = $file1;
30
        $this->file2 = $file2;
31
    }
32
33
    /**
34
     * Returns an array of method objects, indexed by method full name.
35
     *
36
     * @return Method[]
37
     */
38
    public function getMethods(): array
39
    {
40
        $methods = $this->file1->getMethods();
41
        $toMergeMethods = $this->file2->getMethods();
42
43
        foreach ($toMergeMethods as $name => $toMergeMethod) {
44
            $methods[$name] = isset($methods[$name]) ? $methods[$name]->merge($toMergeMethod) : $toMergeMethod;
45
        }
46
47
        return $methods;
48
    }
49
}
50