Extractor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace AppBundle\Service\Extractor;
4
5
use AppBundle\Exception\ExtractorNotExists;
6
use AppBundle\Service\Extractor\Infrastructure\ExtractorInterface;
7
use Symfony\Component\Routing\Router;
8
9
/**
10
 * @author Vehsamrak
11
 */
12
class Extractor
13
{
14
15
    /** @var Router */
16
    private $router;
17
18 9
    public function __construct(Router $router)
19
    {
20 9
        $this->router = $router;
21 9
    }
22
23
    /**
24
     * @param object $entity Entity object
25
     * @throws ExtractorNotExists
26
     */
27 9
    public function extract($entity)
28
    {
29 9
        $entityClassName = (new \ReflectionClass(get_class($entity)))->getShortName();
30 9
        $extractorClassName = __NAMESPACE__ . '\\' . $entityClassName . 'Extractor';
31
32 9
        if (!class_exists($extractorClassName)) {
33
            throw new ExtractorNotExists();
34
        }
35
36
        /** @var ExtractorInterface $extractor */
37 9
        $extractor = new $extractorClassName($this->router);
38
39 9
        return $extractor->extract($entity);
40
    }
41
}
42