ParameterReflectFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getByClassName() 0 14 3
A __construct() 0 3 1
1
<?php
2
3
namespace kalanis\Pohoda\DI;
4
5
use kalanis\Pohoda\PrintRequest;
6
use kalanis\PohodaException;
7
use ReflectionClass;
8
use ReflectionException;
9
10
final class ParameterReflectFactory implements ParameterFactoryInterface
11
{
12 7
    public function __construct(
13
        protected readonly DependenciesFactory $dependenciesFactory,
14 7
    ) {}
15
16
    /**
17
     * {@inheritDoc}
18
     */
19 6
    public function getByClassName(string $className): PrintRequest\Parameter
20
    {
21
        try {
22 6
            $reflection = new ReflectionClass($className);
23 6
            $class = $reflection->newInstance(
24 6
                $this->dependenciesFactory,
25 6
            );
26 1
        } catch (ReflectionException $e) {
27 1
            throw new PohodaException($e->getMessage(), $e->getCode(), $e);
28
        }
29 5
        if (!is_a($class, PrintRequest\Parameter::class)) {
30 1
            throw new PohodaException(sprintf('The class *%s* is not subclass of Parameter', get_class($class)));
31
        }
32 4
        return $class;
33
    }
34
}
35