Coordinate   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 45
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A position() 0 3 1
A __toString() 0 3 1
A calculatePosition() 0 3 1
A row() 0 3 1
A column() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Barryvanveen\CCA;
6
7
class Coordinate
8
{
9
    /** @var int */
10
    protected $row;
11
12
    /** @var int */
13
    protected $column;
14
15
    /** @var int */
16
    protected $columns;
17
18
    /** @var int */
19
    protected $position;
20
21 15
    public function __construct(int $row, int $column, int $columns)
22
    {
23 15
        $this->row = $row;
24 15
        $this->column = $column;
25 15
        $this->columns = $columns;
26 15
        $this->position = $this->calculatePosition();
27 15
    }
28
29 3
    public function __toString(): string
30
    {
31 3
        return sprintf("%d, %d", $this->row, $this->column);
32
    }
33
34 3
    public function row(): int
35
    {
36 3
        return $this->row;
37
    }
38
39 3
    public function column(): int
40
    {
41 3
        return $this->column;
42
    }
43
44 15
    protected function calculatePosition(): int
45
    {
46 15
        return ($this->row * $this->columns) + $this->column;
47
    }
48
49 6
    public function position(): int
50
    {
51 6
        return $this->position;
52
    }
53
}
54