Signature::equalToString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Skrill\ValueObject;
6
7
use Skrill\Exception\InvalidSignatureException;
8
use Skrill\ValueObject\Traits\ValueToStringTrait;
9
10
/**
11
 * Value object for Skrill signature (md5sig or sha2sig).
12
 *
13
 * @see https://www.skrill.com/fileadmin/content/pdf/Skrill_Quick_Checkout_Guide.pdf
14
 */
15
final class Signature
16
{
17
    use ValueToStringTrait;
18
19
    /**
20
     * @param string $value
21
     *
22
     * @throws InvalidSignatureException
23
     */
24
    public function __construct(string $value)
25
    {
26
        $value = trim($value);
27
28
        if (empty($value)) {
29
            throw InvalidSignatureException::emptySignature();
30
        }
31
32
        if (preg_match('/[a-z]/', $value)) {
33
            throw InvalidSignatureException::lowercase();
34
        }
35
36
        $this->value = $value;
37
    }
38
39
    /**
40
     * @param $string
41
     *
42
     * @return bool
43
     */
44
    public function equalToString($string): bool
45
    {
46
        return $string == strval($this->value);
47
    }
48
}
49