Completed
Push — master ( 0ae2b7...d7633b )
by Daniel
03:14
created

AdvancedTrait   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 416
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 55
c 2
b 0
f 1
lcom 2
cbo 0
dl 0
loc 416
ccs 0
cts 116
cp 0
rs 6.8

29 Methods

Rating   Name   Duplication   Size   Complexity  
getArgumentValue() 0 1 ?
setArgument() 0 1 ?
getPdfSettings() 0 1 ?
A isAscii85EncodePages() 0 9 2
A setAscii85EncodePages() 0 6 2
A isAutoPositionEpsFiles() 0 9 2
A setAutoPositionEpsFiles() 0 6 2
A isCreateJobTicket() 0 15 4
A setCreateJobTicket() 0 6 2
A isDetectBlends() 0 9 2
A setDetectBlends() 0 6 2
A isEmitDscWarnings() 0 9 2
A setEmitDscWarnings() 0 6 2
A isLockDistillerParams() 0 9 2
A setLockDistillerParams() 0 6 2
A getOpm() 0 9 2
A setOpm() 0 6 1
A isParseDscComments() 0 9 2
A setParseDscComments() 0 6 2
A isParseDscCommentsForDocInfo() 0 9 2
A setParseDscCommentsForDocInfo() 0 6 2
A isPreserveCopyPage() 0 9 2
A setPreserveCopyPage() 0 6 2
A isPreserveEpsInfo() 0 9 2
A setPreserveEpsInfo() 0 6 2
A isPreserveOpiComments() 0 15 4
A setPreserveOpiComments() 0 6 2
A isUsePrologue() 0 9 2
A setUsePrologue() 0 6 2

How to fix   Complexity   

Complex Class

Complex classes like AdvancedTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AdvancedTrait, and based on these observations, apply Extract Interface, too.

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\DistillerParameters;
9
10
use GravityMedia\Ghostscript\Enum\PdfSettings;
11
12
/**
13
 * The advanced distiller parameters trait
14
 *
15
 * @package GravityMedia\Ghostscript\Devices\DistillerParameters
16
 */
17
trait AdvancedTrait
18
{
19
    /**
20
     * Get argument value
21
     *
22
     * @param string $name
23
     *
24
     * @return string
25
     */
26
    abstract protected function getArgumentValue($name);
27
28
    /**
29
     * Set argument
30
     *
31
     * @param string $argument
32
     *
33
     * @return $this
34
     */
35
    abstract protected function setArgument($argument);
36
37
    /**
38
     * Get PDF settings
39
     *
40
     * @return string
41
     */
42
    abstract public function getPdfSettings();
43
44
    /**
45
     * Whether ASCII85 encode pages
46
     *
47
     * @return bool
48
     */
49
    public function isAscii85EncodePages()
50
    {
51
        $value = $this->getArgumentValue('-dASCII85EncodePages');
52
        if (null === $value) {
53
            return false;
54
        }
55
56
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
57
    }
58
59
    /**
60
     * Set ASCII85 encode pages flag
61
     *
62
     * @param bool $ascii85EncodePages
63
     *
64
     * @return $this
65
     */
66
    public function setAscii85EncodePages($ascii85EncodePages)
67
    {
68
        $this->setArgument(sprintf('-dASCII85EncodePages=%s', $ascii85EncodePages ? 'true' : 'false'));
69
70
        return $this;
71
    }
72
73
    /**
74
     * Whether to auto position EPS files
75
     *
76
     * @return bool
77
     */
78
    public function isAutoPositionEpsFiles()
79
    {
80
        $value = $this->getArgumentValue('-dAutoPositionEPSFiles');
81
        if (null === $value) {
82
            return false;
83
        }
84
85
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
86
    }
87
88
    /**
89
     * Set auto position EPS files flag
90
     *
91
     * @param bool $autoPositionEpsFiles
92
     *
93
     * @return $this
94
     */
95
    public function setAutoPositionEpsFiles($autoPositionEpsFiles)
96
    {
97
        $this->setArgument(sprintf('-dAutoPositionEPSFiles=%s', $autoPositionEpsFiles ? 'true' : 'false'));
98
99
        return $this;
100
    }
101
102
    /**
103
     * Whether to create job ticket
104
     *
105
     * @return bool
106
     */
107
    public function isCreateJobTicket()
108
    {
109
        $value = $this->getArgumentValue('-dCreateJobTicket');
110
        if (null === $value) {
111
            switch ($this->getPdfSettings()) {
112
                case PdfSettings::PRINTER:
113
                case PdfSettings::PREPRESS:
114
                    return true;
115
                default:
116
                    return false;
117
            }
118
        }
119
120
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
121
    }
122
123
    /**
124
     * Set create job ticket flag
125
     *
126
     * @param bool $createJobTicket
127
     *
128
     * @return $this
129
     */
130
    public function setCreateJobTicket($createJobTicket)
131
    {
132
        $this->setArgument(sprintf('-dCreateJobTicket=%s', $createJobTicket ? 'true' : 'false'));
133
134
        return $this;
135
    }
136
137
    /**
138
     * Whether to detect blends
139
     *
140
     * @return bool
141
     */
142
    public function isDetectBlends()
143
    {
144
        $value = $this->getArgumentValue('-dDetectBlends');
145
        if (null === $value) {
146
            return true;
147
        }
148
149
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
150
    }
151
152
    /**
153
     * Set detect blends flag
154
     *
155
     * @param bool $detectBlends
156
     *
157
     * @return $this
158
     */
159
    public function setDetectBlends($detectBlends)
160
    {
161
        $this->setArgument(sprintf('-dDetectBlends=%s', $detectBlends ? 'true' : 'false'));
162
163
        return $this;
164
    }
165
166
    /**
167
     * Whether to emit DSC warnings
168
     *
169
     * @return bool
170
     */
171
    public function isEmitDscWarnings()
172
    {
173
        $value = $this->getArgumentValue('-dEmitDSCWarnings');
174
        if (null === $value) {
175
            return false;
176
        }
177
178
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
179
    }
180
181
    /**
182
     * Set emit DSC warnings flag
183
     *
184
     * @param bool $emitDscWarnings
185
     *
186
     * @return $this
187
     */
188
    public function setEmitDscWarnings($emitDscWarnings)
189
    {
190
        $this->setArgument(sprintf('-dEmitDSCWarnings=%s', $emitDscWarnings ? 'true' : 'false'));
191
192
        return $this;
193
    }
194
195
    /**
196
     * Whether to lock distiller params
197
     *
198
     * @return bool
199
     */
200
    public function isLockDistillerParams()
201
    {
202
        $value = $this->getArgumentValue('-dLockDistillerParams');
203
        if (null === $value) {
204
            return false;
205
        }
206
207
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
208
    }
209
210
    /**
211
     * Set lock distiller params flag
212
     *
213
     * @param bool $lockDistillerParams
214
     *
215
     * @return $this
216
     */
217
    public function setLockDistillerParams($lockDistillerParams)
218
    {
219
        $this->setArgument(sprintf('-dLockDistillerParams=%s', $lockDistillerParams ? 'true' : 'false'));
220
221
        return $this;
222
    }
223
224
    /**
225
     * Get OPM
226
     *
227
     * @return int
228
     */
229
    public function getOpm()
230
    {
231
        $value = $this->getArgumentValue('-dOPM');
232
        if (null === $value) {
233
            return 1;
234
        }
235
236
        return intval($value);
237
    }
238
239
    /**
240
     * Set OPM
241
     *
242
     * @param int $opm
243
     *
244
     * @return $this
245
     */
246
    public function setOpm($opm)
247
    {
248
        $this->setArgument(sprintf('-dOPM=%s', $opm));
249
250
        return $this;
251
    }
252
253
    /**
254
     * Whether to parse DSC comments
255
     *
256
     * @return bool
257
     */
258
    public function isParseDscComments()
259
    {
260
        $value = $this->getArgumentValue('-dParseDSCComments');
261
        if (null === $value) {
262
            return true;
263
        }
264
265
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
266
    }
267
268
    /**
269
     * Set parse DSC comments flag
270
     *
271
     * @param bool $parseDscComments
272
     *
273
     * @return $this
274
     */
275
    public function setParseDscComments($parseDscComments)
276
    {
277
        $this->setArgument(sprintf('-dParseDSCComments=%s', $parseDscComments ? 'true' : 'false'));
278
279
        return $this;
280
    }
281
282
    /**
283
     * Whether to parse DSC comments for doc info
284
     *
285
     * @return bool
286
     */
287
    public function isParseDscCommentsForDocInfo()
288
    {
289
        $value = $this->getArgumentValue('-dParseDSCCommentsForDocInfo');
290
        if (null === $value) {
291
            return true;
292
        }
293
294
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
295
    }
296
297
    /**
298
     * Set parse DSC comments for doc info flag
299
     *
300
     * @param bool $parseDscCommentsForDocInfo
301
     *
302
     * @return $this
303
     */
304
    public function setParseDscCommentsForDocInfo($parseDscCommentsForDocInfo)
305
    {
306
        $this->setArgument(sprintf('-dParseDSCCommentsForDocInfo=%s', $parseDscCommentsForDocInfo ? 'true' : 'false'));
307
308
        return $this;
309
    }
310
311
    /**
312
     * Whether to preserve copy page
313
     *
314
     * @return bool
315
     */
316
    public function isPreserveCopyPage()
317
    {
318
        $value = $this->getArgumentValue('-dPreserveCopyPage');
319
        if (null === $value) {
320
            return true;
321
        }
322
323
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
324
    }
325
326
    /**
327
     * Set preserve copy page flag
328
     *
329
     * @param bool $preserveCopyPage
330
     *
331
     * @return $this
332
     */
333
    public function setPreserveCopyPage($preserveCopyPage)
334
    {
335
        $this->setArgument(sprintf('-dPreserveCopyPage=%s', $preserveCopyPage ? 'true' : 'false'));
336
337
        return $this;
338
    }
339
340
    /**
341
     * Whether to preserve EPS info
342
     *
343
     * @return bool
344
     */
345
    public function isPreserveEpsInfo()
346
    {
347
        $value = $this->getArgumentValue('-dPreserveEPSInfo');
348
        if (null === $value) {
349
            return true;
350
        }
351
352
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
353
    }
354
355
    /**
356
     * Set preserve EPS info flag
357
     *
358
     * @param bool $preserveEpsInfo
359
     *
360
     * @return $this
361
     */
362
    public function setPreserveEpsInfo($preserveEpsInfo)
363
    {
364
        $this->setArgument(sprintf('-dPreserveEPSInfo=%s', $preserveEpsInfo ? 'true' : 'false'));
365
366
        return $this;
367
    }
368
369
    /**
370
     * Whether to preserve OPI comments
371
     *
372
     * @return bool
373
     */
374
    public function isPreserveOpiComments()
375
    {
376
        $value = $this->getArgumentValue('-dPreserveOPIComments');
377
        if (null === $value) {
378
            switch ($this->getPdfSettings()) {
379
                case PdfSettings::PRINTER:
380
                case PdfSettings::PREPRESS:
381
                    return true;
382
                default:
383
                    return false;
384
            }
385
        }
386
387
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
388
    }
389
390
    /**
391
     * Set preserve OPI comments flag
392
     *
393
     * @param bool $preserveOpiComments
394
     *
395
     * @return $this
396
     */
397
    public function setPreserveOpiComments($preserveOpiComments)
398
    {
399
        $this->setArgument(sprintf('-dPreserveOPIComments=%s', $preserveOpiComments ? 'true' : 'false'));
400
401
        return $this;
402
    }
403
404
    /**
405
     * Whether to use prologue
406
     *
407
     * @return bool
408
     */
409
    public function isUsePrologue()
410
    {
411
        $value = $this->getArgumentValue('-dUsePrologue');
412
        if (null === $value) {
413
            return false;
414
        }
415
416
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
417
    }
418
419
    /**
420
     * Set use prologue flag
421
     *
422
     * @param bool $usePrologue
423
     *
424
     * @return $this
425
     */
426
    public function setUsePrologue($usePrologue)
427
    {
428
        $this->setArgument(sprintf('-dUsePrologue=%s', $usePrologue ? 'true' : 'false'));
429
430
        return $this;
431
    }
432
}
433