InjectDoctrineRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 32 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 25
wmc 2
lcom 1
cbo 2
ccs 4
cts 4
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace mxdiModule\Annotation;
3
4
use mxdiModule\Exception\CannotGetValue;
5
use Zend\ServiceManager\ServiceLocatorInterface;
6
7
/**
8
 * @Annotation
9
 * @Target({"PROPERTY", "ANNOTATION", "METHOD"})
10
 */
11
final class InjectDoctrineRepository implements AnnotationInterface
12
{
13
    /**
14
     * FQCN of the entity
15
     * @var string
16
     */
17
    public $value;
18
19
    /**
20
     * Get the value.
21
     *
22
     * @param ServiceLocatorInterface|null $sm
23
     * @return object
24
     *
25
     * @throws CannotGetValue
26
     */
27 2 View Code Duplication
    public function getValue(ServiceLocatorInterface $sm)
28
    {
29
        try {
30 2
            return $sm->get('Doctrine\ORM\EntityManager')->getRepository($this->value);
31 1
        } catch (\Exception $e) {
32 1
            throw CannotGetValue::of(sprintf('repository of %s', $this->value), $e);
33
        }
34
    }
35
}
36