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

Map   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 41
ccs 12
cts 16
cp 0.75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A width() 0 4 1
A height() 0 4 1
A collideWithAnyObstacle() 0 12 3
A normalizePosition() 0 4 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
}