Code Duplication    Length = 69-69 lines in 2 locations

src/Vehicle/App/Mutation/CarMutation.php 1 location

@@ 12-80 (lines=69) @@
9
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
10
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
11
12
class CarMutation implements MutationInterface, AliasedInterface
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 $seatsNumber
32
     * @return Car
33
     * @throws \Doctrine\ORM\NonUniqueResultException
34
     */
35
    public function createCar(string $id, string $manufacturer, string $model, int $seatsNumber): Car
36
    {
37
        if ($car = $this->vehicleRepository->find($id)) {
38
            throw new UserError(sprintf('Car [%s] already exist', AppGlobalId::toGlobalId('Car', $id)));
39
40
            return $car;
41
        }
42
43
        return $this->vehicleRepository->save(
44
            new Car($id, $manufacturer, $model, $seatsNumber)
45
        );
46
    }
47
48
    /**
49
     * @param string $id
50
     * @param string $manufacturer
51
     * @param string $model
52
     * @param int $seatsNumber
53
     * @return Car
54
     * @throws \Doctrine\ORM\NonUniqueResultException
55
     */
56
    public function updateCar(string $id, string $manufacturer, string $model, int $seatsNumber): Car
57
    {
58
        if (!$car = $this->vehicleRepository->find($id)) {
59
            throw new UserError(sprintf('Car [%s] not found', AppGlobalId::toGlobalId('Car', $id)));
60
        }
61
62
        $car
63
            ->setManufacturer($manufacturer)
64
            ->setModel($model)
65
            ->setSeatsNumber($seatsNumber)
66
        ;
67
68
        return $this->vehicleRepository->save($car);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public static function getAliases(): array
75
    {
76
        return [
77
            'resolve' => 'CarMutation',
78
        ];
79
    }
80
}
81

src/Vehicle/App/Mutation/TruckMutation.php 1 location

@@ 12-80 (lines=69) @@
9
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
10
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface;
11
12
class TruckMutation implements MutationInterface, AliasedInterface
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)) {
38
            throw new UserError(sprintf('Truck [%s] already exist', AppGlobalId::toGlobalId('Truck', $id)));
39
40
            return $truck;
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