Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 3 1
A getFormatClass() 0 13 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
use ReflectionClass;
9
use ReflectionException;
10
11
12
/**
13
 * Class Factory
14
 * @package kalanis\kw_mapper\Storage\Shared\FormatFiles
15
 */
16
class Factory
17
{
18 22
    public static function getInstance(): self
19
    {
20 22
        return new self();
21
    }
22
23
    /**
24
     * @param string $path
25
     * @throws MapperException
26
     * @return IFileFormat
27
     */
28 22
    public function getFormatClass(string $path): IFileFormat
29
    {
30
        try {
31
            /** @var class-string $path */
32 22
            $reflect = new ReflectionClass($path);
33 21
            $instance = $reflect->newInstance();
34 1
        } catch (ReflectionException $ex) {
35 1
            throw new MapperException(sprintf('Wanted class *%s* not exists!', $path), $ex->getCode(), $ex);
36
        }
37 21
        if (!$instance instanceof IFileFormat) {
38 1
            throw new MapperException(sprintf('Defined class *%s* is not instance of IFileFormat!', $path));
39
        }
40 20
        return $instance;
41
    }
42
}
43