Completed
Pull Request — master (#2609)
by
unknown
10:03
created

MediaTwigExtension::getFocusPointClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Kunstmaan\MediaBundle\Twig;
4
5
use Kunstmaan\MediaBundle\Entity\EditableMediaWrapper;
6
use Kunstmaan\MediaBundle\Helper\ManipulateImageService;
7
use Twig\Extension\AbstractExtension;
8
use Twig\TwigFunction;
9
10
class MediaTwigExtension extends AbstractExtension
11
{
12
    /** @var ManipulateImageService */
13
    private $manipulateImageService;
14
15
    public function __construct(ManipulateImageService $manipulateImageService)
16
    {
17
        $this->manipulateImageService = $manipulateImageService;
18
    }
19
20
    public function getFunctions()
21
    {
22
        return [
23
            new TwigFunction('cropped_imagine_filter', [$this, 'getCroppedImage']),
24
            new TwigFunction('get_focus_point_class', [$this, 'getFocusPointClass']),
25
        ];
26
    }
27
28
    public function getCroppedImage(EditableMediaWrapper $editableMediaWrapper, string $view = '', string $filter = null)
29
    {
30
        if ($filter) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $filter of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
31
            return $this->manipulateImageService->cropImage($editableMediaWrapper, $view, $filter);
32
        }
33
34
        return $this->manipulateImageService->cropImage($editableMediaWrapper, $view);
35
    }
36
37
    public function getFocusPointClass(EditableMediaWrapper $editableMediaWrapper, string $view = '')
38
    {
39
        return $this->manipulateImageService->getFocusPointClass($editableMediaWrapper, $view);
40
    }
41
}
42