Test Failed
Push — master ( a9de71...77d308 )
by Artem
01:39
created

Locker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 60
ccs 0
cts 17
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A lockData() 0 18 2
A __construct() 0 4 1
A getUnlockedData() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Prozorov\DataVerification;
6
7
use Prozorov\DataVerification\Models\Code;
8
use Prozorov\DataVerification\Types\Address;
9
use Prozorov\DataVerification\Messages\AbstractMessage;
10
use Webmozart\Assert\Assert;
11
12
class Locker
13
{
14
    /**
15
     * @var Configuration $config
16
     */
17
    protected $config;
18
19
    /**
20
     * @var CodeManager $manager
21
     */
22
    protected $manager;
23
24
    public function __construct(Configuration $config)
25
    {
26
        $this->config = $config;
27
        $this->manager = new CodeManager($config);
28
    }
29
30
    /**
31
     * lockData.
32
     *
33
     * @access	public
34
     * @param	array $data - the data that must be locked and verified
35
     * @param	Address	$address - address where we will send one-time password to
36
     * @param	AbstractMessage|string $message - message object or string code for the message factory
37
     * @return	Code
38
     */
39
    public function lockData(array $data, Address $address, $message): Code
40
    {
41
        $code = $this->manager->generate($address, $data);
42
43
        if (is_string($message)) {
44
            $message = $this->config->getMessageFactory()->make($message);
45
        }
46
47
        Assert::isInstanceOf($message, AbstractMessage::class);
48
49
        $message->setCode($code)->setAddress($address);
50
51
        $transport = $this->config->getTransportFactory()
52
            ->make($message->getTransportCode());
53
        
54
        $transport->send($message);
55
56
        return $code;
57
    }
58
59
    /**
60
     * Unlocks the data and gets the protected data
61
     *
62
     * @access	public
63
     * @param	string	$verificationCode	
64
     * @param	string	$pass            	
65
     * @return	array
66
     */
67
    public function getUnlockedData(string $verificationCode, string $pass): array
68
    {
69
        $code = $this->manager->verify($verificationCode, $pass);
70
71
        return $code->getVerificationData();
72
    }
73
}
74