Completed
Pull Request — master (#2609)
by
unknown
70:41 queued 64:09
created

MediaTwigExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 7 1
A getCroppedImage() 0 8 2
A getFocusPointClass() 0 4 1
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