Extractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

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

2 Methods

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