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

CartItemExistsValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 6 2
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