Completed
Pull Request — master (#290)
by
unknown
41:51
created

CartItemExistsValidator::validate()   A

Complexity

Conditions 2
Paths 2

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 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\SyliusShopApiPlugin\Validator;
6
7
use Sylius\Component\Order\Repository\OrderItemRepositoryInterface;
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
final class CartItemExistsValidator extends ConstraintValidator
12
{
13
    /**
14
     * @var OrderItemRepositoryInterface
15
     */
16
    private $orderItemRepository;
17
18
    /**
19
     * @param OrderItemRepositoryInterface $orderItemRepository
20
     */
21
    public function __construct(OrderItemRepositoryInterface $orderItemRepository)
22
    {
23
        $this->orderItemRepository = $orderItemRepository;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function validate($id, Constraint $constraint)
30
    {
31
        if (null === $this->orderItemRepository->find($id)) {
32
            $this->context->addViolation($constraint->message);
33
        }
34
    }
35
}
36