RobotPlacer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
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 MathPHP\LinearAlgebra\Vector;
14
use Psr\Log\LoggerInterface;
15
use Reith\ToyRobot\Domain\Robot\RobotRepositoryInterface;
16
use Reith\ToyRobot\Domain\Robot\Place;
17
use Reith\ToyRobot\Domain\Space\SpaceInterface;
18
use Reith\ToyRobot\Messaging\Command\PlaceRobot;
19
use Reith\ToyRobot\Messaging\Annotation\Subscribe;
20
21
final class RobotPlacer
22
{
23
    private $spaceInterface;
24
25
    private $repository;
26
27
    private $logger;
28
29
    /**
30
     * @param SpaceInterface           $space
31
     * @param RobotRepositoryInterface $repository
32
     * @param LoggerInterface          $logger
33
     */
34 9
    public function __construct(
35
        SpaceInterface $space,
36
        RobotRepositoryInterface $repository,
37
        LoggerInterface $logger
38
    ) {
39 9
        $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...
40 9
        $this->repository = $repository;
41 9
        $this->logger = $logger;
42 9
    }
43
44
    /**
45
     * @Subscribe
46
     *
47
     * @param PlaceRobot $command
48
     */
49 6
    public function handlePlaceRobot(PlaceRobot $command): void
50
    {
51 6
        $robot = $this->space->placeRobot(
52 6
            new Vector($command->getCoordinates()),
53 6
            $command->getDirection()
54
        );
55
56 6
        $this->repository->save($robot);
57
58 6
        $this->logger->info('Robot placed');
59 6
    }
60
}
61