Manipulator::validParams()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Media\Domain\Image;
6
7
use Damax\Media\Domain\Exception\InvalidFile;
8
use Damax\Media\Domain\Model\Media;
9
use Symfony\Component\HttpFoundation\Response;
10
11
abstract class Manipulator
12
{
13
    /**
14
     * Rotates image.
15
     */
16
    const ORIENTATION = 'or';
17
18
    /**
19
     * Flips image.
20
     */
21
    const FLIP = 'flip';
22
23
    /**
24
     * Crops image to specific dimensions.
25
     */
26
    const CROP = 'crop';
27
28
    /**
29
     * Sets image width in pixels.
30
     */
31
    const WIDTH = 'w';
32
33
    /**
34
     * Sets image height in pixels.
35
     */
36
    const HEIGHT = 'h';
37
38
    /**
39
     * Fit image to its target dimensions.
40
     */
41
    const FIT = 'fit';
42
43
    /**
44
     * Multiples overall image size.
45
     */
46
    const PIXEL_RATIO = 'dpr';
47
48
    /**
49
     * Adjusts image brightness.
50
     */
51
    const BRIGHTNESS = 'bri';
52
53
    /**
54
     * Adjusts image contrast.
55
     */
56
    const CONTRAST = 'con';
57
58
    /**
59
     * Adjusts image gamma.
60
     */
61
    const GAMMA = 'gam';
62
63
    /**
64
     * Sharpen image.
65
     */
66
    const SHARPEN = 'sharp';
67
68
    /**
69
     * Applies blur effect.
70
     */
71
    const BLUR = 'blur';
72
73
    /**
74
     * Applies pixelation effect.
75
     */
76
    const PIXELATE = 'pixel';
77
78
    /**
79
     * Applies filter effect.
80
     */
81
    const FILTER = 'filt';
82
83
    /**
84
     * Sets image background color.
85
     */
86
    const BACKGROUND = 'bg';
87
88
    /**
89
     * Adds border.
90
     */
91
    const BORDER = 'border';
92
93
    /**
94
     * Defines quality of image.
95
     */
96
    const QUALITY = 'q';
97
98
    /**
99
     * Encodes image to specific format.
100
     */
101
    const FORMAT = 'fm';
102
103
    /**
104
     * Signature.
105
     */
106
    const SIGNATURE = 's';
107
108
    const ALL = [
109
        self::ORIENTATION,
110
        self::FLIP,
111
        self::CROP,
112
        self::WIDTH,
113
        self::HEIGHT,
114
        self::FIT,
115
        self::PIXEL_RATIO,
116
        self::BRIGHTNESS,
117
        self::CONTRAST,
118
        self::GAMMA,
119
        self::SHARPEN,
120
        self::BLUR,
121
        self::PIXELATE,
122
        self::FILTER,
123
        self::BORDER,
124
        self::QUALITY,
125
        self::FORMAT,
126
        self::SIGNATURE,
127
    ];
128
129
    public static function validParams(array $params): bool
130
    {
131
        return array_diff(array_flip($params), self::ALL) ? false : true;
132
    }
133
134
    /**
135
     * @throws InvalidFile
136
     */
137
    abstract public function processImage(Media $media, array $params): Response;
138
}
139