Completed
Push — IncomprehensibleFinder/base ( 348f7f...2b8e11 )
by Albert
04:07 queued 01:29
created

Couple::hasLessDistanceThan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Kata\Algorithm\Model;
6
7
class Couple
8
{
9
    /** @var Person */
10
    public $younger;
11
12
    /** @var Person */
13
    public $older;
14
15
    /** @var int */
16
    public $birthday_distance_in_seconds;
17
18 4
    public function __construct(Person $first_person, Person $second_person)
19
    {
20 4
        if ($first_person->birthDate() < $second_person->birthDate()) {
21 3
            $this->younger = $first_person;
22 3
            $this->older   = $second_person;
23
        } else {
24 3
            $this->younger = $second_person;
25 3
            $this->older   = $first_person;
26
        }
27
28 4
        $this->birthday_distance_in_seconds =
29 4
            $this->older->birthDate()->getTimestamp() - $this->younger->birthDate()->getTimestamp();
30 4
    }
31
32
    /**
33
     * @return Person
34
     */
35 4
    public function younger()
36
    {
37 4
        return $this->younger;
38
    }
39
40
    /**
41
     * @return Person
42
     */
43 4
    public function older()
44
    {
45 4
        return $this->older;
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function birthdayDistanceInSeconds(): int
52
    {
53
        return $this->birthday_distance_in_seconds;
54
    }
55
56 2
    public function hasGreaterDistanceThan(Couple $another_couple): bool
57
    {
58 2
        return $this->birthday_distance_in_seconds > $another_couple->birthday_distance_in_seconds;
59
    }
60
61 2
    public function hasLessDistanceThan(Couple $another_couple): bool
62
    {
63 2
        return $this->birthday_distance_in_seconds < $another_couple->birthday_distance_in_seconds;
64
    }
65
}
66