Gender   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 4
A isMale() 0 4 1
A equals() 0 4 2
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 Gender extends Embeddable
16
{
17
    /**
18
     * @param string|int $gender Odd for male, even for female.
19
     *
20
     * @throws \InvalidArgumentException
21
     */
22 72
    public function __construct($gender)
23
    {
24 72
        $gender = is_string($gender) ? (int)$gender : $gender;
25
26 72
        if (!is_int($gender) || !in_array($gender, range(1, 8), false)) {
27 22
            throw new \InvalidArgumentException('Unknown gender');
28
        }
29
30 50
        $this->value = (string)$gender;
31 50
    }
32
33
    /**
34
     * @access public
35
     * @return bool
36
     */
37 12
    public function isMale()
38
    {
39 12
        return (int)$this->value % 2 !== 0;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 12
    public function equals(Embeddable $object)
46
    {
47 12
        return get_class($object) === 'Vimishor\Cnp\Gender' && $this->value === (string)$object;
48
    }
49
}
50