Completed
Push — master ( abeb69...f5cf0e )
by recca
02:27
created

Point::compare()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.0488

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 7
cts 8
cp 0.875
rs 8.8571
cc 5
eloc 9
nc 5
nop 2
crap 5.0488
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(Point $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 '>': return $sum > $sum2;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
56 22
            case '>=': return $sum >= $sum2;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
57 17
            case '<': return $sum < $sum2;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
58 17
            case '<=': return $sum <= $sum2;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
59
        }
60
61
        return $sum === $sum2;
62
    }
63
}
64