Passed
Push — master ( e9ba59...c2c890 )
by Tony Karavasilev (Тони
19:20
created

EntityAuthenticationViaTokenTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A authenticateEntity() 0 13 3
1
<?php
2
3
/**
4
 * Trait implementation of the user or client entity authentication via pseudo-random token as passphrase.
5
 */
6
7
namespace CryptoManana\Core\Traits\Containers;
8
9
use \CryptoManana\Core\Interfaces\Containers\EntityAuthenticationInterface as EntityAuthenticationSpecification;
10
11
/**
12
 * Trait EntityAuthenticationViaTokenTrait - Reusable implementation of `EntityAuthenticationInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\Containers\EntityAuthenticationInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\Containers
17
 *
18
 * @mixin EntityAuthenticationSpecification
19
 */
20
trait EntityAuthenticationViaTokenTrait
21
{
22
    /**
23
     * Authenticate a user or a client entity.
24
     *
25
     * @param string $correctPassphrase The correct passphrase information.
26
     * @param string $suppliedPassphrase The supplied passphrase information.
27
     *
28
     * @return bool The identity authentication result.
29
     * @throws \Exception Validation errors.
30
     */
31
    public function authenticateEntity($correctPassphrase, $suppliedPassphrase)
32
    {
33
        if (!is_string($correctPassphrase)) {
1 ignored issue
show
introduced by
The condition is_string($correctPassphrase) is always true.
Loading history...
34
            throw new \InvalidArgumentException(
35
                'The correct token value for verification must be a string or a binary string.'
36
            );
37
        } elseif (!is_string($suppliedPassphrase)) {
1 ignored issue
show
introduced by
The condition is_string($suppliedPassphrase) is always true.
Loading history...
38
            throw new \InvalidArgumentException(
39
                'The supplied user token value must be a string or a binary string.'
40
            );
41
        }
42
43
        return hash_equals($correctPassphrase, $suppliedPassphrase);
44
    }
45
}
46