Test Failed
Push — master ( e79ab4...71fe57 )
by Artem
01:55
created

Locker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 77
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A lockData() 0 18 2
A __construct() 0 4 1
A useFakePass() 0 3 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
    /**
25
     * @var string $otp
26
     */
27
    protected static $otp;
28
29
    /**
30
     * useFakePass.
31
     *
32
     * @access	public static
33
     * @param	string	$code
34
     * @return	void
35
     */
36
    public static function useFakePass(string $otp): void
37
    {
38
        static::$otp = $otp;
39
    }
40
41
    public function __construct(Configuration $config)
42
    {
43
        $this->config = $config;
44
        $this->manager = new CodeManager($config);
45
    }
46
47
    /**
48
     * lockData.
49
     *
50
     * @access	public
51
     * @param	array $data - the data that must be locked and verified
52
     * @param	Address	$address - address where we will send one-time password to
53
     * @param	AbstractMessage|string $message - message object or string code for the message factory
54
     * @return	Code
55
     */
56
    public function lockData(array $data, Address $address, $message): Code
57
    {
58
        $code = $this->manager->generate($address, $data, static::$otp);
59
60
        if (is_string($message)) {
61
            $message = $this->config->getMessageFactory()->make($message);
62
        }
63
64
        Assert::isInstanceOf($message, AbstractMessage::class);
65
66
        $message->setCode($code)->setAddress($address);
67
68
        $transport = $this->config->getTransportFactory()
69
            ->make($message->getTransportCode());
70
        
71
        $transport->send($message);
72
73
        return $code;
74
    }
75
76
    /**
77
     * Unlocks the data and gets the protected data
78
     *
79
     * @access	public
80
     * @param	string	$verificationCode	
81
     * @param	string	$pass            	
82
     * @return	array
83
     */
84
    public function getUnlockedData(string $verificationCode, string $pass): array
85
    {
86
        $code = $this->manager->verify($verificationCode, $pass);
87
88
        return $code->getVerificationData();
89
    }
90
}
91