EntityIdentificationTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A identifyEntity() 0 13 3
1
<?php
2
3
/**
4
 * Trait implementation of the user or client entity identification.
5
 */
6
7
namespace CryptoManana\Core\Traits\Containers;
8
9
use CryptoManana\Core\Interfaces\Containers\EntityIdentificationInterface as EntityVerificationSpecification;
10
11
/**
12
 * Trait EntityIdentificationTrait - Reusable implementation of `EntityIdentificationInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\Containers\EntityIdentificationInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\Containers
17
 *
18
 * @mixin EntityVerificationSpecification
19
 */
20
trait EntityIdentificationTrait
21
{
22
    /**
23
     * Verify the identity of a user or a client entity.
24
     *
25
     * @param string $correctIdentification The correct identification information.
26
     * @param string $suppliedIdentification The supplied identification information.
27
     *
28
     * @return bool The identity verification result.
29
     * @throws \Exception Validation errors.
30
     */
31 27
    public function identifyEntity($correctIdentification, $suppliedIdentification)
32
    {
33 27
        if (!is_string($correctIdentification)) {
34 6
            throw new \InvalidArgumentException(
35 6
                'The correct identity value for verification must be a string or a binary string.'
36 6
            );
37 21
        } elseif (!is_string($suppliedIdentification)) {
38 6
            throw new \InvalidArgumentException(
39 6
                'The supplied identity value must be a string or a binary string.'
40 6
            );
41
        }
42
43 15
        return hash_equals($correctIdentification, $suppliedIdentification);
44
    }
45
}
46