PageRenderingValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace PiedWeb\CMSBundle\Validator\Constraints;
4
5
use PiedWeb\CMSBundle\Service\App;
6
use Symfony\Component\Validator\Constraint;
7
use Symfony\Component\Validator\ConstraintValidator;
8
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
9
10
class PageRenderingValidator extends ConstraintValidator
11
{
12
    private $apps;
13
    private $twig;
14
15
    public function __construct(array $apps, $twig)
16
    {
17
        $this->twig = $twig;
18
        $this->apps = $apps;
19
    }
20
21
    public function validate($value, Constraint $constraint)
22
    {
23
        if (! $constraint instanceof PageRendering) {
24
            throw new UnexpectedTypeException($constraint, PageRendering::class);
25
        }
26
27
        if (false !== $value->getRedirection()) { // si c'est une redir, on check rien
28
            return;
29
        }
30
31
        //$template = App::load($value->getHost(), $this->apps)->getTemplate();
32
33
        try {
34
            $value->getContent()->getBody();
35
        } catch (\Exception $exception) {
36
            $this->context->buildViolation($constraint->message)
37
                ->addViolation();
38
            $this->context->buildViolation($exception->getMessage())
39
                ->addViolation();
40
        }
41
    }
42
}
43