Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

Factory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 3 1
A getFormatClass() 0 10 3
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Shared\FormatFiles;
4
5
6
use kalanis\kw_mapper\Interfaces\IFileFormat;
7
use kalanis\kw_mapper\MapperException;
8
9
10
/**
11
 * Class Factory
12
 * @package kalanis\kw_mapper\Storage\Shared\FormatFiles
13
 */
14
class Factory
15
{
16 21
    public static function getInstance(): self
17
    {
18 21
        return new self();
19
    }
20
21
    /**
22
     * @param string $path
23
     * @throws MapperException
24
     * @return IFileFormat
25
     */
26 21
    public function getFormatClass(string $path): IFileFormat
27
    {
28 21
        if (!class_exists($path)) {
29 1
            throw new MapperException(sprintf('Wanted class *%s* not exists!', $path));
30
        }
31 20
        $instance = new $path();
32 20
        if (!$instance instanceof IFileFormat) {
33 1
            throw new MapperException(sprintf('Defined class *%s* is not instance of IFileFormat!', $path));
34
        }
35 19
        return $instance;
36
    }
37
}
38