Completed
Push — master ( a7b092...3bee99 )
by Michaël
02:47
created

WalkerFactory::addWalker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace TextFile\Factory;
4
5
use TextFile\Exception\InvalidWalkerException;
6
use TextFile\Walker\WalkerInterface;
7
8
/**
9
 * Class WalkerFactory
10
 *
11
 * @package TextFile\Factory
12
 */
13
class WalkerFactory
14
{
15
    /**
16
     * @var WalkerInterface[]
17
     */
18
    protected $walkers = [];
19
20
    /**
21
     * @param string $walkerClass
22
     *
23
     * @return WalkerInterface
24
     * @throws InvalidWalkerException
25
     */
26 3 View Code Duplication
    public function createWalker($walkerClass)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28 3
        if (isset($this->walkers[$walkerClass])) {
29 1
            return $this->walkers[$walkerClass];
30
        }
31
32 3
        if (!isset(class_implements($walkerClass)[WalkerInterface::class])) {
33 1
            throw new InvalidWalkerException();
34
        }
35
36 2
        $this->walkers[$walkerClass] = new $walkerClass;
37
38 2
        return $this->walkers[$walkerClass];
39
    }
40
}
41