Completed
Push — master ( 92f6ed...8d4a88 )
by Joachim
04:27 queued 29s
created

ErrorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
dl 0
loc 24
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createNew() 0 6 1
A createFromConstraintViolation() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusStockMovementPlugin\Factory;
6
7
use Setono\SyliusStockMovementPlugin\Model\ErrorInterface;
8
use Sylius\Component\Resource\Factory\FactoryInterface;
9
use Symfony\Component\Validator\ConstraintViolationInterface;
10
11
final class ErrorFactory implements ErrorFactoryInterface
12
{
13
    /** @var FactoryInterface */
14
    private $decoratedFactory;
15
16
    public function __construct(FactoryInterface $factory)
17
    {
18
        $this->decoratedFactory = $factory;
19
    }
20
21
    public function createNew(): ErrorInterface
22
    {
23
        /** @var ErrorInterface $error */
24
        $error = $this->decoratedFactory->createNew();
25
26
        return $error;
27
    }
28
29
    public function createFromConstraintViolation(ConstraintViolationInterface $constraintViolation): ErrorInterface
30
    {
31
        $error = $this->createNew();
32
        $error->setMessage($constraintViolation->getPropertyPath() . ': ' . $constraintViolation->getMessage());
33
34
        return $error;
35
    }
36
}
37