GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f9d5ee...2b43f5 )
by Jonathan
03:22
created

BaseTransformer   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 233
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 3
Metric Value
wmc 22
c 6
b 1
f 3
lcom 1
cbo 3
dl 0
loc 233
ccs 61
cts 61
cp 1
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
C transform() 0 30 7
A trim() 0 5 2
A resize() 0 4 1
A crop() 0 4 1
A fitIn() 0 4 1
A fullFitIn() 0 4 1
A halign() 0 4 1
A valign() 0 4 1
A smartCrop() 0 4 1
A metadataOnly() 0 4 1
A filters() 0 8 3
A setFactory() 0 4 1
1
<?php
2
3
namespace Jb\Bundle\PhumborBundle\Transformer;
4
5
use Thumbor\Url\BuilderFactory;
6
use Thumbor\Url\Builder;
7
8
/**
9
 * Description of BaseTransformer
10
 *
11
 * @author jobou
12
 */
13
class BaseTransformer
14
{
15
    /**
16
     * Method name for each operation
17
     *
18
     * @var array
19
     */
20
    protected static $filterMethod = array(
21
        'trim' => 'trim',
22
        'crop' => 'crop',
23
        'fit_in' => 'fitIn',
24
        'full_fit_in' => 'fullFitIn',
25
        'resize' => 'resize',
26
        'halign' => 'halign',
27
        'valign' => 'valign',
28
        'smart_crop' => 'smartCrop',
29
        'metadata_only' => 'metadataOnly',
30
        'filters' => 'filters'
31
    );
32
33
    /**
34
     * Phumbor Builder Factory
35
     *
36
     * @var \Thumbor\Url\BuilderFactory
37
     */
38
    protected $factory;
39
40
    /**
41
     * The configured transformations
42
     *
43
     * @var array
44
     */
45
    protected $transformations;
46
47
    /**
48
     * Constructor
49
     *
50
     * @param \Thumbor\Url\BuilderFactory $factory
51
     * @param array $transformations
52
     */
53 21
    public function __construct(BuilderFactory $factory, array $transformations)
54
    {
55 21
        $this->factory = $factory;
56 21
        $this->transformations = $transformations;
57 21
    }
58
59
    /**
60
     * Transform an url or path for thumbor
61
     *
62
     * @param string $orig the original url or path
63
     * @param string $transformation the name of the transformation to apply to the original image
64
     * @param array $overrides an array of additionnal filters to override the ones from the transformation
65
     *
66
     * @return \Thumbor\Url\Builder
67
     *
68
     * @throws \Jb\Bundle\PhumborBundle\Transformer\Exception\UnknownTransformationException
69
     */
70 18
    public function transform($orig, $transformation = null, $overrides = array())
71
    {
72 18
        $url = $this->factory->url($orig);
73 18
        if (is_null($transformation) && count($overrides) == 0) {
74 1
            return $url;
75
        }
76
77
        // Check if a transformation is given without overrides
78 17
        if (!isset($this->transformations[$transformation]) && count($overrides) == 0) {
79 1
            throw new Exception\UnknownTransformationException(
80 1
                "Unknown transformation $transformation. Use on of "
81 1
                . "the following ".implode(', ', array_keys($this->transformations))
82 1
            );
83
        }
84
85
        // Override transformation configuration with custom values
86 16
        $configuration = array();
87 16
        if (isset($this->transformations[$transformation])) {
88 4
            $configuration = $this->transformations[$transformation];
89 4
        }
90 16
        $configuration = array_merge($configuration, $overrides);
91
92
        // Build url from transformation configuration
93 16
        foreach ($configuration as $filter => $arguments) {
94 16
            $method = self::$filterMethod[$filter];
95 16
            $this->$method($url, $arguments);
96 16
        }
97
98 16
        return $url;
99
    }
100
101
    /**
102
     * Apply trim filter
103
     *
104
     * @param \Thumbor\Url\Builder $url
105
     * @param bool|string $args
106
     *
107
     * @return void
108
     */
109 2
    protected function trim(Builder $url, $args)
110
    {
111 2
        $args = (is_string($args)) ? $args : null;
112 2
        $url->trim($args);
113 2
    }
114
115
    /**
116
     * Apply resize filter
117
     *
118
     * @param \Thumbor\Url\Builder $url
119
     * @param array $args
120
     *
121
     * @return void
122
     */
123 5
    protected function resize(Builder $url, $args)
124
    {
125 5
        $url->resize($args['width'], $args['height']);
126 5
    }
127
128
    /**
129
     * Apply crop filter
130
     *
131
     * @param \Thumbor\Url\Builder $url
132
     * @param array $args
133
     *
134
     * @return void
135
     */
136 1
    protected function crop(Builder $url, $args)
137
    {
138 1
        $url->crop($args['top_left_x'], $args['top_left_y'], $args['bottom_right_x'], $args['bottom_right_y']);
139 1
    }
140
141
    /**
142
     * Apply fitIn filter
143
     *
144
     * @param \Thumbor\Url\Builder $url
145
     * @param array $args
146
     *
147
     * @return void
148
     */
149 2
    protected function fitIn(Builder $url, $args)
150
    {
151 2
        $url->fitIn($args['width'], $args['height']);
152 2
    }
153
154
    /**
155
     * Apply fullFitIn filter
156
     *
157
     * @param \Thumbor\Url\Builder $url
158
     * @param array $args
159
     *
160
     * @return void
161
     */
162 1
    protected function fullFitIn(Builder $url, $args)
163
    {
164 1
        $url->fullFitIn($args['width'], $args['height']);
165 1
    }
166
167
    /**
168
     * Apply halign filter
169
     *
170
     * @param \Thumbor\Url\Builder $url
171
     * @param array $args
172
     *
173
     * @return void
174
     */
175 1
    protected function halign(Builder $url, $args)
176
    {
177 1
        $url->halign($args);
178 1
    }
179
180
    /**
181
     * Apply valign filter
182
     *
183
     * @param \Thumbor\Url\Builder $url
184
     * @param array $args
185
     *
186
     * @return void
187
     */
188 1
    protected function valign(Builder $url, $args)
189
    {
190 1
        $url->valign($args);
191 1
    }
192
193
    /**
194
     * Apply smartCrop filter
195
     *
196
     * @param \Thumbor\Url\Builder $url
197
     * @param array $args
198
     *
199
     * @return void
200
     */
201 1
    protected function smartCrop(Builder $url, $args)
202
    {
203 1
        $url->smartCrop($args);
204 1
    }
205
206
    /**
207
     * Request metadata endpoint
208
     *
209
     * @param \Thumbor\Url\Builder $url
210
     * @param array $args
211
     *
212
     * @return void
213
     */
214 2
    protected function metadataOnly(Builder $url, $args)
215
    {
216 2
        $url->metadataOnly($args);
217 2
    }
218
219
    /**
220
     * Apply filters
221
     *
222
     * @param \Thumbor\Url\Builder $url
223
     * @param array $args
224
     *
225
     * @return void
226
     */
227 1
    protected function filters(Builder $url, $args)
228
    {
229 1
        foreach ($args as $arg) {
230 1
            $arguments = (is_array($arg['arguments'])) ? $arg['arguments'] : array($arg['arguments']);
231 1
            array_unshift($arguments, $arg['name']);
232 1
            call_user_func_array(array($url, 'addFilter'), $arguments);
233 1
        }
234 1
    }
235
236
    /**
237
    * Setter allowing for factory override
238
    *
239
    * @param \Thumbor\Url\BuilderFactory $factory
240
    */
241 1
    public function setFactory(BuilderFactory $factory)
242
    {
243 1
        $this->factory = $factory;
244 1
    }
245
}
246