CartItemExistsValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\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