TwicPicsParamsProcessor   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleParamFit() 0 13 3
B finalizeParams() 0 22 8
1
<?php
2
3
namespace A17\Twill\Services\MediaLibrary;
4
5
class TwicPicsParamsProcessor extends AbstractParamsProcessor
6
{
7
    protected $cropFit;
8
9
    public function finalizeParams()
10
    {
11
        if ($this->format) {
12
            $this->params['output'] = $this->format;
13
        }
14
15
        if ($this->quality) {
16
            $this->params['quality'] = $this->quality;
17
        }
18
19
        if ($this->width || $this->height) {
20
            $this->width = $this->width ?: '-';
21
            $this->height = $this->height ?: '-';
22
23
            if ($this->cropFit) {
24
                $this->params['crop'] = "{$this->width}x{$this->height}";
25
            } else {
26
                $this->params['resize'] = "{$this->width}x{$this->height}";
27
            }
28
        }
29
30
        return $this->params;
31
    }
32
33
    protected function handleParamFit($key, $value)
34
    {
35
        if ($value !== 'crop') {
36
            return;
37
        }
38
39
        if (isset($this->params['crop'])) {
40
            return;
41
        }
42
43
        $this->cropFit = true;
44
45
        unset($this->params[$key]);
46
    }
47
}
48