Completed
Push — master ( c54dd1...7d6afc )
by Douglas
03:28
created

RobotPlacer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handlePlaceRobot() 0 8 1
1
<?php
2
3
/**
4
 * (c) 2018 Douglas Reith.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace Reith\ToyRobot\CommandHandler;
12
13
use Reith\ToyRobot\Domain\Robot\RobotRepositoryInterface;
14
use Reith\ToyRobot\Domain\Robot\Robot;
15
use Reith\ToyRobot\Domain\Robot\Place;
16
use Reith\ToyRobot\Domain\Space\SpaceInterface;
17
use Reith\ToyRobot\Messaging\Command\PlaceRobot;
18
use Reith\ToyRobot\Messaging\Annotation\Subscribe;
19
20
class RobotPlacer
21
{
22
    private $spaceInterface;
23
24
    private $robotRepository;
25
26
    /**
27
     * @param SpaceInterface           $space
28
     * @param RobotRepositoryInterface $robotRepository
29
     */
30 2
    public function __construct(
31
        SpaceInterface $space,
32
        RobotRepositoryInterface $robotRepository
33
    ) {
34 2
        $this->space = $space;
0 ignored issues
show
Bug introduced by
The property space does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35 2
        $this->robotRepository = $robotRepository;
36 2
    }
37
38
    /**
39
     * @Subscribe
40
     * @param PlaceRobot $command
41
     */
42 1
    public function handlePlaceRobot(PlaceRobot $command): void
43
    {
44 1
        $robot = $this->space->placeRobot(
45 1
            Place::create($command->getCoordinates())
46
        );
47
48 1
        $this->robotRepository->save($robot);
49 1
    }
50
}
51