Completed
Push — master ( 906add...e6fdb6 )
by
unknown
18:20 queued 11s
created

ImagineCompatibleResizerTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A convertMode() 0 14 6
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Resizer;
15
16
use Imagine\Image\ImageInterface;
17
use Imagine\Image\ImagineInterface;
18
19
/**
20
 * This trait is used to provide compatibility with Imagine >= 1.0.0.
21
 */
22
trait ImagineCompatibleResizerTrait
23
{
24
    /**
25
     * Convert mode for compatibility with imagine >= 1.0.0.
26
     *
27
     * @param int|string $mode
28
     *
29
     * @return int|string
30
     */
31
    final protected function convertMode($mode)
32
    {
33
        if (\is_string($mode) && version_compare(ImagineInterface::VERSION, '1.0.0', '>=')) {
34
            if ('inset' === $mode) {
35
                $mode = ImageInterface::THUMBNAIL_INSET;
36
            } elseif ('outbound' === $mode) {
37
                $mode = ImageInterface::THUMBNAIL_OUTBOUND;
38
            } elseif (is_numeric($mode)) {
39
                $mode = (int) $mode;
40
            }
41
        }
42
43
        return $mode;
44
    }
45
}
46