Completed
Push — ezp25875-richtext_image_embed_... ( c60f8f...849d5b )
by
unknown
19:23
created

IsEmbedImage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 31
rs 10
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setMatchingConfig() 0 8 2
A match() 0 14 3
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\MVC\Symfony\Matcher;
7
8
use eZ\Publish\API\Repository\Values\Content\Location;
9
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
10
use eZ\Publish\Core\MVC\Symfony\Matcher\ViewMatcherInterface;
11
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
12
use eZ\Publish\Core\MVC\Symfony\View\LocationValueView;
13
use eZ\Publish\Core\MVC\Symfony\View\View;
14
15
/**
16
 * A view matcher that matches embed images.
17
 *
18
 * Uses the isEmbedImage embed object parameter.
19
 */
20
class IsEmbedImage implements ViewMatcherInterface
21
{
22
    /**
23
     * @var bool
24
     */
25
    private $isImage;
26
27
    public function setMatchingConfig($matchingConfig)
28
    {
29
        if (!is_bool($matchingConfig)) {
30
            throw new \InvalidArgumentException('The IsImage matcher expects a boolean value');
31
        }
32
33
        $this->isImage = $matchingConfig;
34
    }
35
36
    public function match(View $view)
37
    {
38
        if (!$view->hasParameter('objectParameters')) {
39
            return false;
40
        }
41
42
        $objectParameters = $view->getParameter('objectParameters');
43
44
        if (!isset($objectParameters['isImage'])) {
45
            return false;
46
        }
47
48
        return ($objectParameters['isImage'] === $this->isImage);
49
    }
50
}
51