Completed
Push — master ( cefa14...785c06 )
by Daniel
03:06
created

DistillerParametersTrait::setCalGrayProfile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of the Ghostscript package
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Ghostscript\Devices;
9
10
/**
11
 * The distiller parameters trait
12
 *
13
 * @package GravityMedia\Ghostscript\Devices
14
 */
15
trait DistillerParametersTrait
16
{
17
    /**
18
     * Get argument value
19
     *
20
     * @param string $name
21
     *
22
     * @return string
23
     */
24
    abstract protected function getArgumentValue($name);
25
26
    /**
27
     * Set argument
28
     *
29
     * @param string $argument
30
     *
31
     * @return $this
32
     */
33
    abstract protected function setArgument($argument);
34
35
    /**
36
     * Get auto rotate pages
37
     *
38
     * @return string
39
     */
40
    public function getAutoRotatePages()
41
    {
42
        $value = $this->getArgumentValue('-dAutoRotatePages');
43
        if (null === $value) {
44
            return DistillerParametersInterface::AUTO_ROTATE_PAGES_PAGE_BY_PAGE;
45
        }
46
47
        return substr($value, 1);
48
    }
49
50
    /**
51
     * Set auto rotate pages
52
     *
53
     * @param string $autoRotatePages
54
     *
55
     * @param \InvalidArgumentException
56
     *
57
     * @return $this
58
     */
59 View Code Duplication
    public function setAutoRotatePages($autoRotatePages)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        if (!in_array($autoRotatePages, array(
62
            DistillerParametersInterface::AUTO_ROTATE_PAGES_NONE,
63
            DistillerParametersInterface::AUTO_ROTATE_PAGES_ALL,
64
            DistillerParametersInterface::AUTO_ROTATE_PAGES_PAGE_BY_PAGE
65
        ))
66
        ) {
67
            throw new \InvalidArgumentException('Invalid auto rotate pages argument');
68
        }
69
70
        $this->setArgument(sprintf('-dAutoRotatePages=/%s', $autoRotatePages));
71
72
        return $this;
73
    }
74
75
    /**
76
     * Get binding
77
     *
78
     * @return string
79
     */
80
    public function getBinding()
81
    {
82
        $value = $this->getArgumentValue('-dBinding');
83
        if (null === $value) {
84
            return DistillerParametersInterface::BINDING_LEFT;
85
        }
86
87
        return substr($value, 1);
88
    }
89
90
    /**
91
     * Set binding
92
     *
93
     * @param string $binding
94
     *
95
     * @param \InvalidArgumentException
96
     *
97
     * @return $this
98
     */
99 View Code Duplication
    public function setBinding($binding)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        if (!in_array($binding, array(
102
            DistillerParametersInterface::BINDING_LEFT,
103
            DistillerParametersInterface::BINDING_RIGHT
104
        ))
105
        ) {
106
            throw new \InvalidArgumentException('Invalid binding argument');
107
        }
108
109
        $this->setArgument(sprintf('-dBinding=/%s', $binding));
110
111
        return $this;
112
    }
113
114
    /**
115
     * Get compatibility level
116
     *
117
     * @return float
118
     */
119
    public function getCompatibilityLevel()
120
    {
121
        $value = $this->getArgumentValue('-dCompatibilityLevel');
122
        if (null === $value) {
123
            return 1.4;
124
        }
125
126
        return floatval($value);
127
    }
128
129
    /**
130
     * Set compatibility level
131
     *
132
     * @param float $compatibilityLevel
133
     *
134
     * @return $this
135
     */
136
    public function setCompatibilityLevel($compatibilityLevel)
137
    {
138
        $this->setArgument(sprintf('-dCompatibilityLevel=%s', $compatibilityLevel));
139
140
        return $this;
141
    }
142
143
    /**
144
     * Get core dist version
145
     *
146
     * @return int
147
     */
148
    public function getCoreDistVersion()
149
    {
150
        $value = $this->getArgumentValue('-dCoreDistVersion');
151
        if (null === $value) {
152
            return 4000;
153
        }
154
155
        return intval($value);
156
    }
157
158
    /**
159
     * Set core dist version
160
     *
161
     * @param int $coreDistVersion
162
     *
163
     * @return $this
164
     */
165
    public function setCoreDistVersion($coreDistVersion)
166
    {
167
        $this->setArgument(sprintf('-dCoreDistVersion=%s', $coreDistVersion));
168
169
        return $this;
170
    }
171
172
    /**
173
     * Whether to do thumbnails
174
     *
175
     * @return bool
176
     */
177
    public function getDoThumbnails()
178
    {
179
        $value = $this->getArgumentValue('-dDoThumbnails');
180
        if (null === $value) {
181
            return false;
182
        }
183
184
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
185
    }
186
187
    /**
188
     * Set do thumbnails flag
189
     *
190
     * @param bool $doThumbnails
191
     *
192
     * @return $this
193
     */
194
    public function setDoThumbnails($doThumbnails)
195
    {
196
        $this->setArgument(sprintf('-dDoThumbnails=%s', $doThumbnails ? 'true' : 'false'));
197
198
        return $this;
199
    }
200
201
    /**
202
     * Get end page
203
     *
204
     * @return int
205
     */
206
    public function getEndPage()
207
    {
208
        $value = $this->getArgumentValue('-dEndPage');
209
        if (null === $value) {
210
            return -1;
211
        }
212
213
        return intval($value);
214
    }
215
216
    /**
217
     * Set end page
218
     *
219
     * @param int $endPage
220
     *
221
     * @return $this
222
     */
223
    public function setEndPage($endPage)
224
    {
225
        $this->setArgument(sprintf('-dEndPage=%s', $endPage));
226
227
        return $this;
228
    }
229
230
    /**
231
     * Get image memory
232
     *
233
     * @return int
234
     */
235
    public function getImageMemory()
236
    {
237
        $value = $this->getArgumentValue('-dImageMemory');
238
        if (null === $value) {
239
            return 524288;
240
        }
241
242
        return intval($value);
243
    }
244
245
    /**
246
     * Set image memory
247
     *
248
     * @param int $imageMemory
249
     *
250
     * @return $this
251
     */
252
    public function setImageMemory($imageMemory)
253
    {
254
        $this->setArgument(sprintf('-dImageMemory=%s', $imageMemory));
255
256
        return $this;
257
    }
258
259
    /**
260
     * Get off optimizations
261
     *
262
     * @return int
263
     */
264
    public function getOffOptimizations()
265
    {
266
        $value = $this->getArgumentValue('-dOffOptimizations');
267
        if (null === $value) {
268
            return 0;
269
        }
270
271
        return intval($value);
272
    }
273
274
    /**
275
     * Set off optimizations
276
     *
277
     * @param int $offOptimizations
278
     *
279
     * @return $this
280
     */
281
    public function setOffOptimizations($offOptimizations)
282
    {
283
        $this->setArgument(sprintf('-dOffOptimizations=%s', $offOptimizations));
284
285
        return $this;
286
    }
287
288
    /**
289
     * Whether to optimize
290
     *
291
     * @return bool
292
     */
293
    public function getOptimize()
294
    {
295
        $value = $this->getArgumentValue('-dOptimize');
296
        if (null === $value) {
297
            return false;
298
        }
299
300
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
301
    }
302
303
    /**
304
     * Set optimize flag
305
     *
306
     * @param bool $optimize
307
     *
308
     * @return $this
309
     */
310
    public function setOptimize($optimize)
311
    {
312
        $this->setArgument(sprintf('-dOptimize=%s', $optimize ? 'true' : 'false'));
313
314
        return $this;
315
    }
316
317
    /**
318
     * Get start page
319
     *
320
     * @return int
321
     */
322
    public function getStartPage()
323
    {
324
        $value = $this->getArgumentValue('-dStartPage');
325
        if (null === $value) {
326
            return 1;
327
        }
328
329
        return intval($value);
330
    }
331
332
    /**
333
     * Set start page
334
     *
335
     * @param int $startPage
336
     *
337
     * @return $this
338
     */
339
    public function setStartPage($startPage)
340
    {
341
        $this->setArgument(sprintf('-dStartPage=%s', $startPage));
342
343
        return $this;
344
    }
345
346
    /**
347
     * Whether to use flate compression
348
     *
349
     * @return bool
350
     */
351
    public function getUseFlateCompression()
352
    {
353
        $value = $this->getArgumentValue('-dUseFlateCompression');
354
        if (null === $value) {
355
            return true;
356
        }
357
358
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
359
    }
360
361
    /**
362
     * Set use flate compression flag
363
     *
364
     * @param bool $useFlateCompression
365
     *
366
     * @return $this
367
     */
368
    public function setUseFlateCompression($useFlateCompression)
369
    {
370
        $this->setArgument(sprintf('-dUseFlateCompression=%s', $useFlateCompression ? 'true' : 'false'));
371
372
        return $this;
373
    }
374
}
375