Extractor::extract()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2.0116
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