Completed
Push — master ( 66b796...ebbacf )
by Kamil
17:43 queued 10:16
created

CartItemExistsValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Validator;
4
5
use Sylius\Component\Order\Repository\OrderItemRepositoryInterface;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
9
final class CartItemExistsValidator extends ConstraintValidator
10
{
11
    /**
12
     * @var OrderItemRepositoryInterface
13
     */
14
    private $orderItemRepository;
15
16
    /**
17
     * @param OrderItemRepositoryInterface $orderItemRepository
18
     */
19
    public function __construct(OrderItemRepositoryInterface $orderItemRepository)
20
    {
21
        $this->orderItemRepository = $orderItemRepository;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function validate($id, Constraint $constraint)
28
    {
29
        if (null === $this->orderItemRepository->find($id)) {
30
            $this->context->addViolation($constraint->message);
31
        }
32
    }
33
}
34