ImplodeKeys   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 2
b 0
f 0
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 3
A __construct() 0 6 1
1
<?php
2
3
namespace kalanis\kw_auth_forms\Rules;
4
5
6
use kalanis\kw_accounts\Interfaces\ICert;
7
use kalanis\kw_accounts\Interfaces\IUser;
8
use kalanis\kw_auth_sources\Interfaces\IStatus;
9
use kalanis\kw_rules\Exceptions\RuleException;
10
use kalanis\kw_rules\Interfaces\IValidate;
11
12
13
/**
14
 * Class ImplodeKeys
15
 * @package kalanis\kw_auth_forms\Rules
16
 * Check digest value for preselected inputs - validate certificate
17
 */
18
class ImplodeKeys extends ARule
19
{
20
    protected IUser $userSource;
21
    protected ICert $certSource;
22
    protected IStatus $libStatus;
23
    protected string $glue = '';
24
25 8
    public function __construct(IUser $userSource, ICert $certSource, IStatus $libStatus, string $glue = '|')
26
    {
27 8
        $this->userSource = $userSource;
28 8
        $this->certSource = $certSource;
29 8
        $this->libStatus = $libStatus;
30 8
        $this->glue = $glue;
31 8
    }
32
33 8
    public function validate(IValidate $entry): void
34
    {
35 8
        if (!$this->libStatus->allowCert($this->userSource->getStatus())) {
36 4
            throw new RuleException($this->errorText);
37
        }
38 4
        $col = implode($this->glue, $this->sentInputs() + [$this->certSource->getSalt()]);
39 4
        if (1 !== openssl_verify($col, strval($entry->getValue()), $this->certSource->getPubKey(), OPENSSL_ALGO_SHA256)) {
40 1
            throw new RuleException($this->errorText);
41
        }
42 3
    }
43
}
44