AbstractKey   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 56
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toBinary() 0 4 1
A toHexadecimal() 0 4 1
A __toString() 0 4 1
validateKey() 0 1 ?
1
<?php
2
/*
3
 * This file is part of the DUKPT package.
4
 *
5
 * Copyright (c) 2016-2017 Tonic Health <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace TonicForHealth\DUKPT\Key;
12
13
/**
14
 * Class AbstractKey
15
 *
16
 * @author Vitalii Ekert <[email protected]>
17
 */
18
abstract class AbstractKey implements KeyInterface
19
{
20
    /**
21
     * The key as a binary data string
22
     *
23
     * @var string
24
     */
25
    private $binKey;
26
27
    /**
28
     * AbstractKey constructor.
29
     *
30
     * @param string $binKey The key as a binary data string
31
     *
32
     * @throws \InvalidArgumentException If the provided key has a wrong size
33
     */
34 31
    public function __construct($binKey)
35
    {
36 31
        $this->binKey = $this->validateKey($binKey);
37 23
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 23
    public function toBinary()
43
    {
44 23
        return $this->binKey;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 10
    public function toHexadecimal()
51
    {
52 10
        return strtoupper(bin2hex($this->toBinary()));
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 10
    public function __toString()
59
    {
60 10
        return $this->toHexadecimal();
61
    }
62
63
    /**
64
     * Validate the specified key
65
     *
66
     * @param string $binKey The specified key as a binary data string
67
     *
68
     * @throws \InvalidArgumentException If the provided key has a wrong size
69
     *
70
     * @return string Returns the validated key as a binary data string
71
     */
72
    abstract protected function validateKey($binKey);
73
}
74