Park   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 14 3
A validate() 0 6 2
1
<?php
2
namespace Parking\Console\Command;
3
/**
4
 * Class Park
5
 *
6
 * @author Rafael Queiroz <[email protected]>
7
 * @package Parking\Console\Command
8
 */
9
class Park implements Command
10
{
11
12
    /**
13
     * @var \Parking\Domain\Repository\ParkingRepository
14
     */
15
    private $repository;
16
17
    /**
18
     * Park constructor.
19
     * @param \Parking\Domain\Repository\ParkingRepository $repository
20
     */
21
    public function __construct(\Parking\Domain\Repository\ParkingRepository $repository)
22
    {
23
        $this->repository = $repository;
24
    }
25
26
    /**
27
     * Execute method
28
     *
29
     * @param $input
30
     * @param $output
31
     * @return string
32
     */
33
    public function execute($input, $output)
34
    {
35
        $this->validate($input);
36
37
        $parking = $this->repository->get();
38
        $slot = $parking->park(new \Parking\Domain\Car($input[0], $input[1]));
39
        $this->repository->store($parking);
40
41
        if ($slot !== false) {
42
            $output = "Allocated slot number: " . $slot;
43
        }
44
45
        return $output ? $output : "Sorry, parking lot is full";
46
    }
47
48
    /**
49
     * Validate method
50
     *
51
     * @param $input
52
     * @throws \Exception
53
     */
54
    protected function validate($input)
55
    {
56
        if (count ($input) < 2) {
57
            throw new \Exception('You need pass a plate and colour for park');
58
        }
59
    }
60
}