Completed
Push — master ( 6e52f0...d9a404 )
by Alexandre
02:29
created

Guard::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 06/01/2018
6
 * Time: 17:02
7
 */
8
9
namespace OAuth2OLD\Endpoint\Server\Authentication;
10
11
12
use OAuth2OLD\Role\Client;
13
use OAuth2OLD\Role\Client\Type\ClientPassword;
0 ignored issues
show
Bug introduced by
The type OAuth2OLD\Role\Client\Type\ClientPassword was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Psr\Http\Message\ServerRequestInterface;
15
16
class Guard
17
{
18
    /**
19
     * @var array
20
     */
21
    private $authenticators;
22
23
    public function __construct(array $authenticators = [])
24
    {
25
        $this->authenticators = $authenticators;
26
    }
27
28
    public function requireAuthentication(Client $client) : bool {
29
        /**
30
         * @var AuthenticatorInterface $authenticator
31
         */
32
        foreach ($this->authenticators as $authenticator) {
33
            if($authenticator->requireAuthentication($client)) {
34
                return true;
35
            }
36
        }
37
        return false;
38
    }
39
40
    public function authenticate(ServerRequestInterface $request) : ?Client
41
    {
42
        /**
43
         * @var AuthenticatorInterface $authenticator
44
         */
45
        foreach ($this->authenticators as $authenticator) {
46
            if($client = $authenticator->authenticate($request)) {
47
                return $client;
48
            }
49
        }
50
        return null;
51
    }
52
53
}