Completed
Push — master ( c9e866...91e961 )
by Samuel
10s
created

VehicleFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 35.48 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 22
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createCarInput() 11 11 1
A createCar() 0 9 1
A createTruckInput() 11 11 1
A createTruck() 0 9 1

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
3
namespace App\Vehicle\App\Factory;
4
5
use App\Common\App\Transformer\AppGlobalId;
6
use App\Vehicle\Domain\Car;
7
use App\Vehicle\Domain\Input\CarInput;
8
use App\Vehicle\Domain\Input\TruckInput;
9
use App\Vehicle\Domain\Truck;
10
use Overblog\GraphQLBundle\Definition\Argument;
11
12
class VehicleFactory
13
{
14
    /**
15
     * @param Argument $argument
16
     * @return CarInput
17
     */
18 View Code Duplication
    public static function createCarInput(Argument $argument): CarInput
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...
19
    {
20
        $input = $argument->offsetGet('input');
21
22
        return new CarInput(
23
            AppGlobalId::getIdFromGlobalId($input['id']),
24
            $input['manufacturer'],
25
            $input['model'],
26
            $input['seats_number']
27
        );
28
    }
29
30
    /**
31
     * @param CarInput $input
32
     * @return Car
33
     */
34
    public static function createCar(CarInput $input): Car
35
    {
36
        return new Car(
37
            $input->getId(),
38
            $input->getManufacturer(),
39
            $input->getModel(),
40
            $input->getSeatsNumber()
41
        );
42
    }
43
44
    /**
45
     * @param Argument $argument
46
     * @return TruckInput
47
     */
48 View Code Duplication
    public static function createTruckInput(Argument $argument): TruckInput
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...
49
    {
50
        $input = $argument->offsetGet('input');
51
52
        return new TruckInput(
53
            AppGlobalId::getIdFromGlobalId($input['id']),
54
            $input['manufacturer'],
55
            $input['model'],
56
            $input['maximum_load']
57
        );
58
    }
59
60
    /**
61
     * @param TruckInput $input
62
     * @return Truck
63
     */
64
    public static function createTruck(TruckInput $input): Truck
65
    {
66
        return new Truck(
67
            $input->getId(),
68
            $input->getManufacturer(),
69
            $input->getModel(),
70
            $input->getMaximumLoad()
71
        );
72
    }
73
}
74