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.

DistillerParameters/GrayImageCompressionTrait.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\DistillerParameters;
9
10
use GravityMedia\Ghostscript\Enum\ColorAndGrayImageFilter;
11
use GravityMedia\Ghostscript\Enum\ImageDownsampleType;
12
use GravityMedia\Ghostscript\Enum\PdfSettings;
13
14
/**
15
 * The grayscale image compression distiller parameters trait.
16
 *
17
 * @package GravityMedia\Ghostscript\Device\DistillerParameters
18
 *
19
 * @link    http://ghostscript.com/doc/current/Ps2pdf.htm
20
 */
21 View Code Duplication
trait GrayImageCompressionTrait
0 ignored issues
show
This class 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...
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
     * Whether to anti alias grayscale images
50
     *
51
     * @return bool
52
     */
53 2
    public function isAntiAliasGrayImages()
54
    {
55 2
        $value = $this->getArgumentValue('-dAntiAliasGrayImages');
56 2
        if (null === $value) {
57 2
            return false;
58
        }
59
60 2
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
61
    }
62
63
    /**
64
     * Set anti alias grayscale images flag
65
     *
66
     * @param bool $antiAliasGrayImages
67
     *
68
     * @return $this
69
     */
70 2
    public function setAntiAliasGrayImages($antiAliasGrayImages)
71
    {
72 2
        $this->setArgument(sprintf('-dAntiAliasGrayImages=%s', $antiAliasGrayImages ? 'true' : 'false'));
73
74 2
        return $this;
75
    }
76
77
    /**
78
     * Whether to auto filter grayscale images
79
     *
80
     * @return bool
81
     */
82 2
    public function isAutoFilterGrayImages()
83
    {
84 2
        $value = $this->getArgumentValue('-dAutoFilterGrayImages');
85 2
        if (null === $value) {
86 2
            return true;
87
        }
88
89 2
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
90
    }
91
92
    /**
93
     * Set auto filter grayscale images flag
94
     *
95
     * @param bool $autoFilterGrayImages
96
     *
97
     * @return $this
98
     */
99 2
    public function setAutoFilterGrayImages($autoFilterGrayImages)
100
    {
101 2
        $this->setArgument(sprintf('-dAutoFilterGrayImages=%s', $autoFilterGrayImages ? 'true' : 'false'));
102
103 2
        return $this;
104
    }
105
106
    /**
107
     * Whether to downsample gray images
108
     *
109
     * @return bool
110
     */
111 10
    public function isDownsampleGrayImages()
112
    {
113 10
        $value = $this->getArgumentValue('-dDownsampleGrayImages');
114 10
        if (null === $value) {
115 10
            switch ($this->getPdfSettings()) {
116 10
                case PdfSettings::SCREEN:
117 9
                case PdfSettings::EBOOK:
118 4
                    return true;
119 3
                default:
120 6
                    return false;
121 3
            }
122
        }
123
124 10
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
125
    }
126
127
    /**
128
     * Set downsample gray images flag
129
     *
130
     * @param bool $downsampleGrayImages
131
     *
132
     * @return $this
133
     */
134 10
    public function setDownsampleGrayImages($downsampleGrayImages)
135
    {
136 10
        $this->setArgument(sprintf('-dDownsampleGrayImages=%s', $downsampleGrayImages ? 'true' : 'false'));
137
138 10
        return $this;
139
    }
140
141
    /**
142
     * Whether to encode grayscale images
143
     *
144
     * @return bool
145
     */
146 2
    public function isEncodeGrayImages()
147
    {
148 2
        $value = $this->getArgumentValue('-dEncodeGrayImages');
149 2
        if (null === $value) {
150 2
            return true;
151
        }
152
153 2
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
154
    }
155
156
    /**
157
     * Set encode grayscale images flag
158
     *
159
     * @param bool $encodeGrayImages
160
     *
161
     * @return $this
162
     */
163 2
    public function setEncodeGrayImages($encodeGrayImages)
164
    {
165 2
        $this->setArgument(sprintf('-dEncodeGrayImages=%s', $encodeGrayImages ? 'true' : 'false'));
166
167 2
        return $this;
168
    }
169
170
    /**
171
     * Get gray image depth
172
     *
173
     * @return int
174
     */
175 2
    public function getGrayImageDepth()
176
    {
177 2
        $value = $this->getArgumentValue('-dGrayImageDepth');
178 2
        if (null === $value) {
179 2
            return -1;
180
        }
181
182 2
        return intval($value);
183
    }
184
185
    /**
186
     * Set gray image depth
187
     *
188
     * @param int $grayImageDepth
189
     *
190
     * @return $this
191
     */
192 2
    public function setGrayImageDepth($grayImageDepth)
193
    {
194 2
        $this->setArgument(sprintf('-dGrayImageDepth=%s', $grayImageDepth));
195
196 2
        return $this;
197
    }
198
199
    /**
200
     * Get gray image downsample threshold
201
     *
202
     * @return float
203
     */
204 2
    public function getGrayImageDownsampleThreshold()
205
    {
206 2
        $value = $this->getArgumentValue('-dGrayImageDownsampleThreshold');
207 2
        if (null === $value) {
208 2
            return 1.5;
209
        }
210
211 2
        return floatval($value);
212
    }
213
214
    /**
215
     * Set gray image downsample threshold
216
     *
217
     * @param float $grayImageDownsampleThreshold
218
     *
219
     * @return $this
220
     */
221 2
    public function setGrayImageDownsampleThreshold($grayImageDownsampleThreshold)
222
    {
223 2
        $this->setArgument(sprintf('-dGrayImageDownsampleThreshold=%s', $grayImageDownsampleThreshold));
224
225 2
        return $this;
226
    }
227
228
    /**
229
     * Get gray image downsample type
230
     *
231
     * @return string
232
     */
233 10
    public function getGrayImageDownsampleType()
234
    {
235 10
        $value = $this->getArgumentValue('-dGrayImageDownsampleType');
236 10
        if (null === $value) {
237 10
            switch ($this->getPdfSettings()) {
238 10
                case PdfSettings::SCREEN:
239 2
                    return ImageDownsampleType::AVERAGE;
240 8
                case PdfSettings::EBOOK:
241 7
                case PdfSettings::PRINTER:
242 6
                case PdfSettings::PREPRESS:
243 6
                    return ImageDownsampleType::BICUBIC;
244 1
                default:
245 2
                    return ImageDownsampleType::SUBSAMPLE;
246 1
            }
247
        }
248
249 10
        return ltrim($value, '/');
250
    }
251
252
    /**
253
     * Set gray image downsample type
254
     *
255
     * @param string $grayImageDownsampleType
256
     *
257
     * @throws \InvalidArgumentException
258
     *
259
     * @return $this
260
     */
261 12
    public function setGrayImageDownsampleType($grayImageDownsampleType)
262
    {
263 12
        $grayImageDownsampleType = ltrim($grayImageDownsampleType, '/');
264 12
        if (!in_array($grayImageDownsampleType, ImageDownsampleType::values())) {
265 2
            throw new \InvalidArgumentException('Invalid grayscale image downsample type argument');
266
        }
267
268 10
        $this->setArgument(sprintf('-dGrayImageDownsampleType=/%s', $grayImageDownsampleType));
269
270 10
        return $this;
271
    }
272
273
    /**
274
     * Get gray image filter
275
     *
276
     * @return string
277
     */
278 6
    public function getGrayImageFilter()
279
    {
280 6
        $value = $this->getArgumentValue('-dGrayImageFilter');
281 6
        if (null === $value) {
282 2
            return ColorAndGrayImageFilter::DCT_ENCODE;
283
        }
284
285 4
        return ltrim($value, '/');
286
    }
287
288
    /**
289
     * Set gray image filter
290
     *
291
     * @param string $grayImageFilter
292
     *
293
     * @throws \InvalidArgumentException
294
     *
295
     * @return $this
296
     */
297 6
    public function setGrayImageFilter($grayImageFilter)
298
    {
299 6
        $grayImageFilter = ltrim($grayImageFilter, '/');
300 6
        if (!in_array($grayImageFilter, ColorAndGrayImageFilter::values())) {
301 2
            throw new \InvalidArgumentException('Invalid grayscale image filter argument');
302
        }
303
304 4
        $this->setArgument(sprintf('-dGrayImageFilter=/%s', $grayImageFilter));
305
306 4
        return $this;
307
    }
308
309
    /**
310
     * Get gray image resolution
311
     *
312
     * @return int
313
     */
314 10
    public function getGrayImageResolution()
315
    {
316 10
        $value = $this->getArgumentValue('-dGrayImageResolution');
317 10
        if (null === $value) {
318 10
            switch ($this->getPdfSettings()) {
319 10
                case PdfSettings::EBOOK:
320 2
                    return 150;
321 8
                case PdfSettings::PRINTER:
322 7
                case PdfSettings::PREPRESS:
323 4
                    return 300;
324 2
                default:
325 4
                    return 72;
326 2
            }
327
        }
328
329 10
        return intval($value);
330
    }
331
332
    /**
333
     * Set gray image resolution
334
     *
335
     * @param int $grayImageResolution
336
     *
337
     * @return $this
338
     */
339 10
    public function setGrayImageResolution($grayImageResolution)
340
    {
341 10
        $this->setArgument(sprintf('-dGrayImageResolution=%s', $grayImageResolution));
342
343 10
        return $this;
344
    }
345
}
346