CreateParkingLot   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 16.36 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 9
loc 55
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 13 1
A validate() 9 9 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Parking\Console\Command;
3
/**
4
 * Class CreateParkingLot
5
 *
6
 * @author Rafael Queiroz <[email protected]>
7
 * @package Parking\Console\Command
8
 */
9
class CreateParkingLot implements Command
10
{
11
12
    /**
13
     * @var \Parking\Domain\Repository\ParkingRepository
14
     */
15
    private $repository;
16
17
    /**
18
     * CreateParkingLot 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 = new \Parking\Domain\Parking(array_map(function() {
38
            return new \Parking\Domain\Slot();
39
        }, range(1, $input[0])));
40
41
        $this->repository->store($parking);
42
        $output = "Created a parking lot with {$input[0]} slots";
43
44
        return $output;
45
    }
46
47
    /**
48
     * Validate method
49
     *
50
     * @param $input
51
     * @throws \Exception
52
     */
53 View Code Duplication
    protected function validate($input)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        if (!$input) {
56
            throw new \Exception('You need pass a number of a slot');
57
        }
58
        if ($input[0] < 1) {
59
            throw new \Exception('You need pass a integer more than 0 for slot');
60
        }
61
    }
62
63
}
64