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

WriterFactory::createWriter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
3
namespace TextFile\Factory;
4
5
use TextFile\Exception\InvalidWriterException;
6
use TextFile\Writer\WriterInterface;
7
8
/**
9
 * Class WriterFactory
10
 *
11
 * @package TextFile\Factory
12
 */
13
class WriterFactory
14
{
15
    /**
16
     * @var WriterInterface[]
17
     */
18
    protected $writers = [];
19
20
    /**
21
     * @param string $writerClass
22
     *
23
     * @return WriterInterface
24
     * @throws InvalidWriterException
25
     */
26 3 View Code Duplication
    public function createWriter($writerClass)
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->writers[$writerClass])) {
29 1
            return $this->writers[$writerClass];
30
        }
31
32 3
        if (!isset(class_implements($writerClass)[WriterInterface::class])) {
33 1
            throw new InvalidWriterException();
34
        }
35
36 2
        $this->writers[$writerClass] = new $writerClass;
37
38 2
        return $this->writers[$writerClass];
39
    }
40
}
41