ParameterReflectFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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