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

Extractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
ccs 9
cts 10
cp 0.9
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extract() 0 13 2
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