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

RobotPlacer::handlePlaceRobot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 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