Leave   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 9
loc 54
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1
rs 10

3 Methods

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