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

VehicleMutation::getAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Vehicle\App\Mutation;
4
5
use App\Common\App\Transformer\AppGlobalId;
6
use App\Vehicle\Domain\Car;
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
class VehicleMutation 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 $globalId
29
     * @return string
30
     * @throws \Doctrine\ORM\NonUniqueResultException
31
     */
32
    public function deleteVehicle(string $globalId): string
33
    {
34
        $id = AppGlobalId::getIdFromGlobalId($globalId);
35
36
        if (!$vehicle = $this->vehicleRepository->find($id)) {
37
            throw new UserError(sprintf('Vehicle [%s] not found', $globalId));
38
        }
39
40
        $this->vehicleRepository->delete($vehicle);
41
42
        return $globalId;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public static function getAliases(): array
49
    {
50
        return [
51
            'resolve' => 'VehicleMutation',
52
        ];
53
    }
54
}
55