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

ErrorFactory::createNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
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