ColorBlockController::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 10
1
<?php
2
3
namespace Limsum\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Limsum\ColorBlock\ColorBlockMaker;
7
8
class ColorBlockController extends LimsumController
9
{
10
11
    /**
12
     * @var string
13
     */
14
    public static string $withParameterName = 'w';
15
16
    /**
17
     * @var string
18
     */
19
    public static string $heightParameterName = 'h';
20
21
    /**
22
     * @var string
23
     */
24
    public static string $colorParameterName = 'c';
25
26
    /**
27
     * @param  string  $extension
28
     * @param  Request  $request
29
     *
30
     * @return mixed
31
     */
32 2
    public function __invoke(string $extension, Request $request)
33
    {
34 2
        if (! in_array($extension, config('lorem-image.drivers.color-block.extensions', []))) {
35
            abort(404);
36
        }
37
38 2
        return (new ColorBlockMaker(
39
            $extension,
40 2
            $request->get(static::$withParameterName, 100) ?? 100,
41 2
            $request->get(static::$heightParameterName, 100) ?? 100,
42 2
            $request->get(static::$colorParameterName, '#808080') ?: '#808080',
43 2
        ))->image();
44
    }
45
}
46