Completed
Push — develop ( 191b0e...b270a8 )
by Alexandru
01:33
created

Checksum::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 8.8571
cc 5
eloc 5
nc 4
nop 1
crap 5
1
<?php
2
/**
3
 * Copyright 2017 Alexandru Guzinschi <[email protected]>
4
 *
5
 * This software may be modified and distributed under the terms
6
 * of the MIT license. See the LICENSE file for details.
7
 */
8
namespace Vimishor\Cnp;
9
10
use Gentle\Embeddable\Embeddable;
11
12
/**
13
 * @author Alexandru Guzinschi <[email protected]>
14
 */
15
final class Checksum extends Embeddable
16
{
17
    /**
18
     * @param string|int $number
19
     *
20
     * @throws \InvalidArgumentException
21
     */
22 46
    public function __construct($number)
23
    {
24 46
        $number = is_int($number) ? (string)$number : $number;
25
26 46
        if (!is_string($number) || !ctype_digit($number) || mb_strlen($number) !== 1) {
27 22
            throw new \InvalidArgumentException('Expected a string of length 1');
28
        }
29
30 24
        $this->value = $number;
31 24
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 12
    public function equals(Embeddable $object)
37
    {
38 12
        return get_class($object) === 'Vimishor\Cnp\Checksum' && $this->value === (string)$object;
39
    }
40
}
41