Authenticator::authenticate()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 20
rs 9.4285
cc 3
eloc 11
nc 4
nop 1
1
<?php
2
3
namespace T4web\Authentication\Service;
4
5
use Zend\Authentication\AuthenticationService;
6
use Zend\Authentication\Result as AuthResult;
7
use Zend\Authentication\Adapter\AdapterInterface;
8
use Zend\EventManager\EventManager;
9
use T4web\Authentication\AuthenticationEvent;
10
11
class Authenticator extends AuthenticationService
12
{
13
    /**
14
     * @var AuthenticationService
15
     */
16
    protected $authService;
17
18
    /**
19
     * @var AuthResult
20
     */
21
    protected $result;
22
23
    /**
24
     * @var AdapterInterface
25
     */
26
    protected $adapter;
27
28
    /**
29
     * @param AuthenticationService $authService
30
     * @param AdapterInterface $adapter
31
     */
32
    public function __construct(AuthenticationService $authService, AdapterInterface $adapter)
33
    {
34
        $this->authService = $authService;
35
        $this->adapter = $adapter;
36
    }
37
38
    /**
39
     * @param AdapterInterface|null $adapter
40
     * @return AuthResult
41
     */
42
    public function authenticate(AdapterInterface $adapter = null)
43
    {
44
        $event = new AuthenticationEvent();
45
        $event->setTarget($this);
46
47
        if (!$adapter) {
48
            $adapter = $this->adapter;
49
        }
50
51
        if ($adapter) {
52
            $event->setAdapter($adapter);
53
        }
54
55
        $eventManager = new EventManager();
56
        $eventManager->setIdentifiers(get_class($this));
57
58
        $eventManager->trigger($event);
59
60
        return $event->getResult();
61
    }
62
63
    /**
64
     * @return AdapterInterface
65
     */
66
    public function getAdapter()
67
    {
68
        return $this->adapter;
69
    }
70
71
    public function hasIdentity()
72
    {
73
        return $this->authService->hasIdentity();
74
    }
75
}
76