Api   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 86
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setImageManager() 0 4 1
A getImageManager() 0 4 1
A setManipulators() 0 10 3
A getManipulators() 0 4 1
A run() 0 12 2
1
<?php
2
3
namespace League\Glide\Api;
4
5
use Intervention\Image\ImageManager;
6
use InvalidArgumentException;
7
use League\Glide\Manipulators\ManipulatorInterface;
8
9
class Api implements ApiInterface
10
{
11
    /**
12
     * Intervention image manager.
13
     * @var ImageManager
14
     */
15
    protected $imageManager;
16
17
    /**
18
     * Collection of manipulators.
19
     * @var array
20
     */
21
    protected $manipulators;
22
23
    /**
24
     * Create API instance.
25
     * @param ImageManager $imageManager Intervention image manager.
26
     * @param array        $manipulators Collection of manipulators.
27
     */
28
    public function __construct(ImageManager $imageManager, array $manipulators)
29
    {
30
        $this->setImageManager($imageManager);
31
        $this->setManipulators($manipulators);
32
    }
33
34
    /**
35
     * Set the image manager.
36
     * @param ImageManager $imageManager Intervention image manager.
37
     */
38
    public function setImageManager(ImageManager $imageManager)
39
    {
40
        $this->imageManager = $imageManager;
41
    }
42
43
    /**
44
     * Get the image manager.
45
     * @return ImageManager Intervention image manager.
46
     */
47
    public function getImageManager()
48
    {
49
        return $this->imageManager;
50
    }
51
52
    /**
53
     * Set the manipulators.
54
     * @param array $manipulators Collection of manipulators.
55
     */
56
    public function setManipulators(array $manipulators)
57
    {
58
        foreach ($manipulators as $manipulator) {
59
            if (!($manipulator instanceof ManipulatorInterface)) {
60
                throw new InvalidArgumentException('Not a valid manipulator.');
61
            }
62
        }
63
64
        $this->manipulators = $manipulators;
65
    }
66
67
    /**
68
     * Get the manipulators.
69
     * @return array Collection of manipulators.
70
     */
71
    public function getManipulators()
72
    {
73
        return $this->manipulators;
74
    }
75
76
    /**
77
     * Perform image manipulations.
78
     * @param  string $source Source image binary data.
79
     * @param  array  $params The manipulation params.
80
     * @return string Manipulated image binary data.
81
     */
82
    public function run($source, array $params)
83
    {
84
        $image = $this->imageManager->make($source);
85
86
        foreach ($this->manipulators as $manipulator) {
87
            $manipulator->setParams($params);
88
89
            $image = $manipulator->run($image);
90
        }
91
92
        return $image->getEncoded();
93
    }
94
}
95