PageRenderingValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 30
rs 10
c 4
b 0
f 0
ccs 0
cts 22
cp 0
wmc 5

2 Methods

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