Inject   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 31
wmc 3
lcom 1
cbo 2
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 14 3
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 Inject implements AnnotationInterface
12
{
13
    /** @var string */
14
    public $value;
15
16
    /** @var bool */
17
    public $invokable = false;
18
19
    /**
20
     * Get the value.
21
     *
22
     * @param ServiceLocatorInterface|null $sm
23
     * @return object
24
     *
25
     * @throws CannotGetValue
26
     */
27 3
    public function getValue(ServiceLocatorInterface $sm)
28
    {
29 3
        $serviceName = $this->value;
30
31 3
        if ($this->invokable) {
32 1
            return new $serviceName;
33
        }
34
35
        try {
36 2
            return $sm->get($serviceName);
37 1
        } catch (\Exception $e) {
38 1
            throw CannotGetValue::of($this->value, $e);
39
        }
40
    }
41
}
42