Passed
Push — refactor_render ( 1be99d...7e011e )
by Mattia
09:18
created

Side   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 18
c 1
b 0
f 1
dl 0
loc 67
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromRawPoints() 0 5 1
A getBottomRight() 0 3 1
A __construct() 0 4 1
A getWidth() 0 3 1
A getHeight() 0 3 1
A getTopLeft() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Image\Components;
6
7
use Minepic\Image\Point;
8
9
class Side
10
{
11
    public const TOP = 'TOP';
12
    public const BOTTOM = 'BOTTOM';
13
    public const FRONT = 'FRONT';
14
    public const BACK = 'BACK';
15
    public const RIGHT = 'RIGHT';
16
    public const LEFT = 'LEFT';
17
18
    /** @var Point */
19
    protected Point $topLeft;
20
21
    /** @var Point */
22
    protected Point $bottomRight;
23
24
    /**
25
     * @param Point $topLeft
26
     * @param Point $bottomRight
27
     */
28
    public function __construct(Point $topLeft, Point $bottomRight)
29
    {
30
        $this->topLeft = $topLeft;
31
        $this->bottomRight = $bottomRight;
32
    }
33
34
    /**
35
     * @return Point
36
     */
37
    public function getTopLeft(): Point
38
    {
39
        return $this->topLeft;
40
    }
41
42
    /**
43
     * @return Point
44
     */
45
    public function getBottomRight(): Point
46
    {
47
        return $this->bottomRight;
48
    }
49
50
    /**
51
     * @return int
52
     */
53
    public function getWidth(): int
54
    {
55
        return $this->bottomRight->getX() - $this->topLeft->getX();
56
    }
57
58
    /**
59
     * @return int
60
     */
61
    public function getHeight(): int
62
    {
63
        return $this->bottomRight->getY() - $this->topLeft->getY();
64
    }
65
66
    /**
67
     * @param array $rawPoints
68
     *
69
     * @return Side
70
     */
71
    public static function fromRawPoints(array $rawPoints): self
72
    {
73
        return new self(
74
            new Point($rawPoints[0][0], $rawPoints[0][1]),
75
            new Point($rawPoints[1][0], $rawPoints[1][1])
76
        );
77
    }
78
}
79