ClientAuthenticator::isClientValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/**
3
 * @author Boris Guéry <[email protected]>
4
 */
5
6
namespace Bgy\OAuth2;
7
8
use Bgy\OAuth2\Storage\ClientNotFound;
9
use Bgy\OAuth2\Storage\ClientStorage;
10
11
class ClientAuthenticator
12
{
13
    private $clientStorage;
14
15
    public function __construct(ClientStorage $storage)
16
    {
17
        $this->clientStorage = $storage;
18
    }
19
20
    public function isClientValid($clientId, $clientSecret)
21
    {
22
        try {
23
            $client = $this->clientStorage->findById($clientId);
24
        } catch (ClientNotFound $e) {
25
26
            return false;
27
        }
28
29
        return ((string) $client->getSecret() === (string) $clientSecret);
30
    }
31
}
32