Issues (9)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Device/DistillerParametersTrait.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Device;
9
10
use GravityMedia\Ghostscript\Enum\AutoRotatePages;
11
use GravityMedia\Ghostscript\Enum\Binding;
12
use GravityMedia\Ghostscript\Enum\PdfSettings;
13
14
/**
15
 * The general distiller parameters trait.
16
 *
17
 * @package GravityMedia\Ghostscript\Devices
18
 *
19
 * @link    http://ghostscript.com/doc/current/Ps2pdf.htm
20
 */
21
trait DistillerParametersTrait
22
{
23
    /**
24
     * Get argument value
25
     *
26
     * @param string $name
27
     *
28
     * @return null|string
29
     */
30
    abstract protected function getArgumentValue($name);
31
32
    /**
33
     * Set argument
34
     *
35
     * @param string $argument
36
     *
37
     * @return $this
38
     */
39
    abstract protected function setArgument($argument);
40
41
    /**
42
     * Get PDF settings
43
     *
44
     * @return string
45
     */
46
    abstract public function getPdfSettings();
47
48
    /**
49
     * Get auto rotate pages
50
     *
51
     * @return string
52
     */
53 10
    public function getAutoRotatePages()
54
    {
55 10
        $value = $this->getArgumentValue('-dAutoRotatePages');
56 10
        if (null === $value) {
57 10
            switch ($this->getPdfSettings()) {
58 10
                case PdfSettings::EBOOK:
59 2
                    return AutoRotatePages::ALL;
60 8
                case PdfSettings::PRINTER:
61 7
                case PdfSettings::PREPRESS:
62 4
                    return AutoRotatePages::NONE;
63 2
                default:
64 4
                    return AutoRotatePages::PAGE_BY_PAGE;
65 2
            }
66
        }
67
68 10
        return ltrim($value, '/');
69
    }
70
71
    /**
72
     * Set auto rotate pages
73
     *
74
     * @param string $autoRotatePages
75
     *
76
     * @param \InvalidArgumentException
77
     *
78
     * @return $this
79
     */
80 12
    public function setAutoRotatePages($autoRotatePages)
81
    {
82 12
        $autoRotatePages = ltrim($autoRotatePages, '/');
83 12
        if (!in_array($autoRotatePages, AutoRotatePages::values())) {
84 2
            throw new \InvalidArgumentException('Invalid auto rotate pages argument');
85
        }
86
87 10
        $this->setArgument(sprintf('-dAutoRotatePages=/%s', $autoRotatePages));
88
89 10
        return $this;
90
    }
91
92
    /**
93
     * Get binding
94
     *
95
     * @return string
96
     */
97 2
    public function getBinding()
98
    {
99 2
        $value = $this->getArgumentValue('-dBinding');
100 2
        if (null === $value) {
101 2
            return Binding::LEFT;
102
        }
103
104 2
        return ltrim($value, '/');
105
    }
106
107
    /**
108
     * Set binding
109
     *
110
     * @param string $binding
111
     *
112
     * @param \InvalidArgumentException
113
     *
114
     * @return $this
115
     */
116 4
    public function setBinding($binding)
117
    {
118 4
        $binding = ltrim($binding, '/');
119 4
        if (!in_array($binding, Binding::values())) {
120 2
            throw new \InvalidArgumentException('Invalid binding argument');
121
        }
122
123 2
        $this->setArgument(sprintf('-dBinding=/%s', $binding));
124
125 2
        return $this;
126
    }
127
128
    /**
129
     * Get compatibility level
130
     *
131
     * @return float
132
     */
133 10 View Code Duplication
    public function getCompatibilityLevel()
0 ignored issues
show
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...
134
    {
135 10
        $value = $this->getArgumentValue('-dCompatibilityLevel');
136 10
        if (null === $value) {
137 10
            switch ($this->getPdfSettings()) {
138 10
                case PdfSettings::SCREEN:
139 2
                    return 1.3;
140 4
                default:
141 8
                    return 1.4;
142 4
            }
143
        }
144
145 10
        return floatval($value);
146
    }
147
148
    /**
149
     * Set compatibility level
150
     *
151
     * @param float $compatibilityLevel
152
     *
153
     * @return $this
154
     */
155 10
    public function setCompatibilityLevel($compatibilityLevel)
156
    {
157 10
        $this->setArgument(sprintf('-dCompatibilityLevel=%s', $compatibilityLevel));
158
159 10
        return $this;
160
    }
161
162
    /**
163
     * Get core dist version
164
     *
165
     * @return int
166
     */
167 2
    public function getCoreDistVersion()
168
    {
169 2
        $value = $this->getArgumentValue('-dCoreDistVersion');
170 2
        if (null === $value) {
171 2
            return 4000;
172
        }
173
174 2
        return intval($value);
175
    }
176
177
    /**
178
     * Set core dist version
179
     *
180
     * @param int $coreDistVersion
181
     *
182
     * @return $this
183
     */
184 2
    public function setCoreDistVersion($coreDistVersion)
185
    {
186 2
        $this->setArgument(sprintf('-dCoreDistVersion=%s', $coreDistVersion));
187
188 2
        return $this;
189
    }
190
191
    /**
192
     * Whether to do thumbnails
193
     *
194
     * @return bool
195
     */
196 10
    public function isDoThumbnails()
197
    {
198 10
        $value = $this->getArgumentValue('-dDoThumbnails');
199 10
        if (null === $value) {
200 10
            switch ($this->getPdfSettings()) {
201 10
                case PdfSettings::PREPRESS:
202 2
                    return true;
203 4
                default:
204 8
                    return false;
205 4
            }
206
        }
207
208 10
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
209
    }
210
211
    /**
212
     * Set do thumbnails flag
213
     *
214
     * @param bool $doThumbnails
215
     *
216
     * @return $this
217
     */
218 10
    public function setDoThumbnails($doThumbnails)
219
    {
220 10
        $this->setArgument(sprintf('-dDoThumbnails=%s', $doThumbnails ? 'true' : 'false'));
221
222 10
        return $this;
223
    }
224
225
    /**
226
     * Get end page
227
     *
228
     * @return int
229
     */
230 2
    public function getEndPage()
231
    {
232 2
        $value = $this->getArgumentValue('-dEndPage');
233 2
        if (null === $value) {
234 2
            return -1;
235
        }
236
237 2
        return intval($value);
238
    }
239
240
    /**
241
     * Set end page
242
     *
243
     * @param int $endPage
244
     *
245
     * @return $this
246
     */
247 2
    public function setEndPage($endPage)
248
    {
249 2
        $this->setArgument(sprintf('-dEndPage=%s', $endPage));
250
251 2
        return $this;
252
    }
253
254
    /**
255
     * Get image memory
256
     *
257
     * @return int
258
     */
259 2
    public function getImageMemory()
260
    {
261 2
        $value = $this->getArgumentValue('-dImageMemory');
262 2
        if (null === $value) {
263 2
            return 524288;
264
        }
265
266 2
        return intval($value);
267
    }
268
269
    /**
270
     * Set image memory
271
     *
272
     * @param int $imageMemory
273
     *
274
     * @return $this
275
     */
276 2
    public function setImageMemory($imageMemory)
277
    {
278 2
        $this->setArgument(sprintf('-dImageMemory=%s', $imageMemory));
279
280 2
        return $this;
281
    }
282
283
    /**
284
     * Get off optimizations
285
     *
286
     * @return int
287
     */
288 2
    public function getOffOptimizations()
289
    {
290 2
        $value = $this->getArgumentValue('-dOffOptimizations');
291 2
        if (null === $value) {
292 2
            return 0;
293
        }
294
295 2
        return intval($value);
296
    }
297
298
    /**
299
     * Set off optimizations
300
     *
301
     * @param int $offOptimizations
302
     *
303
     * @return $this
304
     */
305 2
    public function setOffOptimizations($offOptimizations)
306
    {
307 2
        $this->setArgument(sprintf('-dOffOptimizations=%s', $offOptimizations));
308
309 2
        return $this;
310
    }
311
312
    /**
313
     * Whether to optimize
314
     *
315
     * @return bool
316
     */
317 10
    public function isOptimize()
318
    {
319 10
        $value = $this->getArgumentValue('-dOptimize');
320 10
        if (null === $value) {
321 10
            switch ($this->getPdfSettings()) {
322 10
                case PdfSettings::SCREEN:
323 9
                case PdfSettings::EBOOK:
324 8
                case PdfSettings::PRINTER:
325 7
                case PdfSettings::PREPRESS:
326 8
                    return true;
327 1
                default:
328 2
                    return false;
329 1
            }
330
        }
331
332 10
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
333
    }
334
335
    /**
336
     * Set optimize flag
337
     *
338
     * @param bool $optimize
339
     *
340
     * @return $this
341
     */
342 10
    public function setOptimize($optimize)
343
    {
344 10
        $this->setArgument(sprintf('-dOptimize=%s', $optimize ? 'true' : 'false'));
345
346 10
        return $this;
347
    }
348
349
    /**
350
     * Get start page
351
     *
352
     * @return int
353
     */
354 2
    public function getStartPage()
355
    {
356 2
        $value = $this->getArgumentValue('-dStartPage');
357 2
        if (null === $value) {
358 2
            return 1;
359
        }
360
361 2
        return intval($value);
362
    }
363
364
    /**
365
     * Set start page
366
     *
367
     * @param int $startPage
368
     *
369
     * @return $this
370
     */
371 2
    public function setStartPage($startPage)
372
    {
373 2
        $this->setArgument(sprintf('-dStartPage=%s', $startPage));
374
375 2
        return $this;
376
    }
377
378
    /**
379
     * Whether to use flate compression
380
     *
381
     * @return bool
382
     */
383 2
    public function isUseFlateCompression()
384
    {
385 2
        $value = $this->getArgumentValue('-dUseFlateCompression');
386 2
        if (null === $value) {
387 2
            return true;
388
        }
389
390 2
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
391
    }
392
393
    /**
394
     * Set use flate compression flag
395
     *
396
     * @param bool $useFlateCompression
397
     *
398
     * @return $this
399
     */
400 2
    public function setUseFlateCompression($useFlateCompression)
401
    {
402 2
        $this->setArgument(sprintf('-dUseFlateCompression=%s', $useFlateCompression ? 'true' : 'false'));
403
404 2
        return $this;
405
    }
406
}
407