Completed
Push — Rover/albertg ( 3c48fc )
by Albert
01:56
created

Map::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Kata\Rover\Domain\Model;
4
5
class Map
6
{
7
    private $width;
8
    private $height;
9
    private $obstacles;
10
11 2
    public function __construct(int $a_width, int $a_height, Obstacle ...$obstacles_array)
12
    {
13 2
        $this->width     = $a_width;
14 2
        $this->height    = $a_height;
15 2
        $this->obstacles = $obstacles_array;
16 2
    }
17
18
    public function width(): int
19
    {
20
        return $this->width;
21
    }
22
23
    public function height(): int
24
    {
25
        return $this->height;
26
    }
27
28 2
    public function collideWithAnyObstacle(Position $a_position): bool
29
    {
30 2
        foreach ($this->obstacles as $obstacle)
31
        {
32 2
            if ($obstacle->collide($a_position))
33
            {
34 2
                return true;
35
            }
36
        }
37
38 2
        return false;
39
    }
40
41 2
    public function normalizePosition(Position $new_position): Position
42
    {
43 2
        return $new_position;
44
    }
45
}