Completed
Push — master ( 2d9e7d...e8a8b9 )
by Samuel
8s
created

TruckMutation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Vehicle\App\Mutation;
4
5
use App\Common\App\Transformer\AppGlobalId;
6
use App\Vehicle\Domain\Truck;
7
use App\Vehicle\Domain\VehicleRepositoryInterface;
8
use GraphQL\Error\UserError;
9
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
10
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
11
12 View Code Duplication
class TruckMutation implements MutationInterface, AliasedInterface
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    /**
15
     * @var VehicleRepositoryInterface
16
     */
17
    private $vehicleRepository;
18
19
    /**
20
     * @param VehicleRepositoryInterface $vehicleRepository
21
     */
22
    public function __construct(VehicleRepositoryInterface $vehicleRepository)
23
    {
24
        $this->vehicleRepository = $vehicleRepository;
25
    }
26
27
    /**
28
     * @param string $id
29
     * @param string $manufacturer
30
     * @param string $model
31
     * @param int $maximumLoad
32
     * @return Truck
33
     * @throws \Doctrine\ORM\NonUniqueResultException
34
     */
35
    public function createTruck(string $id, string $manufacturer, string $model, int $maximumLoad): Truck
36
    {
37
        if ($truck = $this->vehicleRepository->find($id)) {
0 ignored issues
show
Unused Code introduced by
$truck is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
            throw new UserError(sprintf('Truck [%s] already exist', AppGlobalId::toGlobalId('Truck', $id)));
39
40
            return $truck;
0 ignored issues
show
Unused Code introduced by
return $truck; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
41
        }
42
43
        return $this->vehicleRepository->save(
44
            new Truck($id, $manufacturer, $model, $maximumLoad)
45
        );
46
    }
47
48
    /**
49
     * @param string $id
50
     * @param string $manufacturer
51
     * @param string $model
52
     * @param int $maximumLoad
53
     * @return Truck
54
     * @throws \Doctrine\ORM\NonUniqueResultException
55
     */
56
    public function updateTruck(string $id, string $manufacturer, string $model, int $maximumLoad): Truck
57
    {
58
        if (!$truck = $this->vehicleRepository->find($id)) {
59
            throw new UserError(sprintf('Truck [%s] not found', AppGlobalId::toGlobalId('Truck', $id)));
60
        }
61
62
        $truck
63
            ->setManufacturer($manufacturer)
64
            ->setModel($model)
65
            ->setMaximumLoad($maximumLoad)
66
        ;
67
68
        return $this->vehicleRepository->save($truck);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public static function getAliases(): array
75
    {
76
        return [
77
            'resolve' => 'TruckMutation',
78
        ];
79
    }
80
}
81