InjectIdentity::getValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
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 InjectIdentity implements AnnotationInterface
12
{
13
    /**
14
     * Get the value.
15
     *
16
     * @param ServiceLocatorInterface $sm
17
     * @return object|null
18
     *
19
     * @throws CannotGetValue
20
     */
21
    public function getValue(ServiceLocatorInterface $sm)
22
    {
23
        try {
24
            return $sm->get('Zend\Authentication\AuthenticationService')->getIdentity();
25
        } catch (\Exception $e) {
26
            throw CannotGetValue::of('identity', $e);
27
        }
28
    }
29
}
30