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

AdvancedTrait   B

Complexity

Total Complexity 51

Size/Duplication

Total Lines 397
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 51
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 397
ccs 0
cts 104
cp 0
rs 8.3206

28 Methods

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