Point::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Recca0120\Twzipcode;
4
5
class Point
6
{
7
    /**
8
     * $x.
9
     *
10
     * @var int
11
     */
12
    public $x = 0;
13
14
    /**
15
     * $y.
16
     *
17
     * @var int
18
     */
19
    public $y = 0;
20
21
    /**
22
     * __construct.
23
     *
24
     * @param int $x
25
     * @param int $y
26
     */
27 37
    public function __construct($x = 0, $y = 0)
28
    {
29 37
        $this->x = $x;
30 37
        $this->y = $y;
31 37
    }
32
33
    /**
34
     * empty.
35
     *
36
     * @return bool
37
     */
38 34
    public function isEmpty()
39
    {
40 34
        return $this->x === 0 && $this->y === 0;
41
    }
42
43
    /**
44
     * compare.
45
     *
46
     * @param Point $point
47
     * @param string $operator
48
     * @return bool
49
     */
50 22
    public function compare(self $point, $operator = '=')
51
    {
52 22
        $sum = $this->x * 10 + $this->y;
53 22
        $sum2 = $point->x * 10 + $point->y;
54
        switch ($operator) {
55 22
            case '>':
56
                return $sum > $sum2;
57 22
            case '>=':
58 10
                return $sum >= $sum2;
59 17
            case '<':
60
                return $sum < $sum2;
61 17
            case '<=':
62 17
                return $sum <= $sum2;
63
        }
64
65
        return $sum === $sum2;
66
    }
67
}
68