Completed
Push — IncomprehensibleFinder/SandraA... ( c60dee )
by Albert
02:20
created

Couple::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 0
cts 11
cp 0
rs 9.8666
cc 3
nc 2
nop 2
crap 12
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Kata\Algorithm;
6
7
final class Couple
8
{
9
    /** @var Person */
10
    public $older_person;
11
12
    /** @var Person */
13
    public $younger_person;
14
15
    /** @var int */
16
    public $age_difference;
17
18
    public function __construct(
19
        ?Person $first_person = null,
20
        ?Person $second_person = null
21
    ) {
22
        if (null === $first_person || null === $second_person)
23
        {
24
            return;
25
        }
26
27
        $this->older_person = $this->getOlderPerson($first_person, $second_person);
28
        $this->younger_person = $this->getYoungerPerson($first_person, $second_person);
29
    }
30
31
    private function getOlderPerson(
32
        Person $first_person,
33
        Person $second_person
34
    ) {
35
        if ($first_person->getBirthDate() < $second_person->getBirthDate())
36
        {
37
            return $first_person;
38
39
        }
40
41
        return $second_person;
42
    }
43
44
    private function getYoungerPerson(
45
        Person $first_person,
46
        Person $second_person
47
    ) {
48
        if ($first_person->getBirthDate() < $second_person->getBirthDate())
49
        {
50
            return $second_person;
51
        }
52
53
        return $first_person;
54
    }
55
}
56