Passed
Push — master ( e008f3...ac9d28 )
by Petr
03:49
created

Extractor::__construct()   A

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