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/MonoImageCompressionTrait.php (2 issues)

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\ImageDownsampleType;
11
use GravityMedia\Ghostscript\Enum\MonoImageFilter;
12
use GravityMedia\Ghostscript\Enum\PdfSettings;
13
14
/**
15
 * The monochrome image compression distiller parameters trait.
16
 *
17
 * @package GravityMedia\Ghostscript\Device\DistillerParameters
18
 *
19
 * @link    http://ghostscript.com/doc/current/Ps2pdf.htm
20
 */
21
trait MonoImageCompressionTrait
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 monochrome images
50
     *
51
     * @return bool
52
     */
53 2
    public function isAntiAliasMonoImages()
54
    {
55 2
        $value = $this->getArgumentValue('-dAntiAliasMonoImages');
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 monochrome images flag
65
     *
66
     * @param bool $antiAliasMonoImages
67
     *
68
     * @return $this
69
     */
70 2
    public function setAntiAliasMonoImages($antiAliasMonoImages)
71
    {
72 2
        $this->setArgument(sprintf('-dAntiAliasMonoImages=%s', $antiAliasMonoImages ? 'true' : 'false'));
73
74 2
        return $this;
75
    }
76
77
    /**
78
     * Whether to downsample monochrome images
79
     *
80
     * @return bool
81
     */
82 10
    public function isDownsampleMonoImages()
83
    {
84 10
        $value = $this->getArgumentValue('-dDownsampleMonoImages');
85 10
        if (null === $value) {
86 10
            switch ($this->getPdfSettings()) {
87 10
                case PdfSettings::SCREEN:
88 9
                case PdfSettings::EBOOK:
89 4
                    return true;
90 3
                default:
91 6
                    return false;
92 3
            }
93
        }
94
95 10
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
96
    }
97
98
    /**
99
     * Set downsample monochrome images flag
100
     *
101
     * @param bool $downsampleMonoImages
102
     *
103
     * @return $this
104
     */
105 10
    public function setDownsampleMonoImages($downsampleMonoImages)
106
    {
107 10
        $this->setArgument(sprintf('-dDownsampleMonoImages=%s', $downsampleMonoImages ? 'true' : 'false'));
108
109 10
        return $this;
110
    }
111
112
    /**
113
     * Whether to encode monochrome images
114
     *
115
     * @return bool
116
     */
117 2
    public function isEncodeMonoImages()
118
    {
119 2
        $value = $this->getArgumentValue('-dEncodeMonoImages');
120 2
        if (null === $value) {
121 2
            return true;
122
        }
123
124 2
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
125
    }
126
127
    /**
128
     * Set encode monochrome images flag
129
     *
130
     * @param bool $encodeMonoImages
131
     *
132
     * @return $this
133
     */
134 2
    public function setEncodeMonoImages($encodeMonoImages)
135
    {
136 2
        $this->setArgument(sprintf('-dEncodeMonoImages=%s', $encodeMonoImages ? 'true' : 'false'));
137
138 2
        return $this;
139
    }
140
141
    /**
142
     * Get monochrome image depth
143
     *
144
     * @return int
145
     */
146 2
    public function getMonoImageDepth()
147
    {
148 2
        $value = $this->getArgumentValue('-dMonoImageDepth');
149 2
        if (null === $value) {
150 2
            return -1;
151
        }
152
153 2
        return intval($value);
154
    }
155
156
    /**
157
     * Set monochrome image depth
158
     *
159
     * @param int $monoImageDepth
160
     *
161
     * @return $this
162
     */
163 2
    public function setMonoImageDepth($monoImageDepth)
164
    {
165 2
        $this->setArgument(sprintf('-dMonoImageDepth=%s', $monoImageDepth));
166
167 2
        return $this;
168
    }
169
170
    /**
171
     * Get monochrome image downsample threshold
172
     *
173
     * @return float
174
     */
175 2
    public function getMonoImageDownsampleThreshold()
176
    {
177 2
        $value = $this->getArgumentValue('-dMonoImageDownsampleThreshold');
178 2
        if (null === $value) {
179 2
            return 1.5;
180
        }
181
182 2
        return floatval($value);
183
    }
184
185
    /**
186
     * Set monochrome image downsample threshold
187
     *
188
     * @param float $monoImageDownsampleThreshold
189
     *
190
     * @return $this
191
     */
192 2
    public function setMonoImageDownsampleThreshold($monoImageDownsampleThreshold)
193
    {
194 2
        $this->setArgument(sprintf('-dMonoImageDownsampleThreshold=%s', $monoImageDownsampleThreshold));
195
196 2
        return $this;
197
    }
198
199
    /**
200
     * Get monochrome image downsample type
201
     *
202
     * @return string
203
     */
204 10 View Code Duplication
    public function getMonoImageDownsampleType()
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...
205
    {
206 10
        $value = $this->getArgumentValue('-dMonoImageDownsampleType');
207 10
        if (null === $value) {
208 10
            switch ($this->getPdfSettings()) {
209 10
                case PdfSettings::PREPRESS:
210 2
                    return ImageDownsampleType::BICUBIC;
211 4
                default:
212 8
                    return ImageDownsampleType::SUBSAMPLE;
213 4
            }
214
        }
215
216 10
        return ltrim($value, '/');
217
    }
218
219
    /**
220
     * Set monochrome image downsample type
221
     *
222
     * @param string $monoImageDownsampleType
223
     *
224
     * @throws \InvalidArgumentException
225
     *
226
     * @return $this
227
     */
228 12
    public function setMonoImageDownsampleType($monoImageDownsampleType)
229
    {
230 12
        $monoImageDownsampleType = ltrim($monoImageDownsampleType, '/');
231 12
        if (!in_array($monoImageDownsampleType, ImageDownsampleType::values())) {
232 2
            throw new \InvalidArgumentException('Invalid monochrome image downsample type argument');
233
        }
234
235 10
        $this->setArgument(sprintf('-dMonoImageDownsampleType=/%s', $monoImageDownsampleType));
236
237 10
        return $this;
238
    }
239
240
    /**
241
     * Get monochrome image filter
242
     *
243
     * @return string
244
     */
245 8
    public function getMonoImageFilter()
246
    {
247 8
        $value = $this->getArgumentValue('-dMonoImageFilter');
248 8
        if (null === $value) {
249 2
            return MonoImageFilter::CCITT_FAX_ENCODE;
250
        }
251
252 6
        return ltrim($value, '/');
253
    }
254
255
    /**
256
     * Set monochrome image filter
257
     *
258
     * @param string $monoImageFilter
259
     *
260
     * @throws \InvalidArgumentException
261
     *
262
     * @return $this
263
     */
264 8
    public function setMonoImageFilter($monoImageFilter)
265
    {
266 8
        $monoImageFilter = ltrim($monoImageFilter, '/');
267 8
        if (!in_array($monoImageFilter, MonoImageFilter::values())) {
268 2
            throw new \InvalidArgumentException('Invalid monochrome image filter argument');
269
        }
270
271 6
        $this->setArgument(sprintf('-dMonoImageFilter=/%s', $monoImageFilter));
272
273 6
        return $this;
274
    }
275
276
    /**
277
     * Get monochrome image resolution
278
     *
279
     * @return int
280
     */
281 10 View Code Duplication
    public function getMonoImageResolution()
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...
282
    {
283 10
        $value = $this->getArgumentValue('-dMonoImageResolution');
284 10
        if (null === $value) {
285 10
            switch ($this->getPdfSettings()) {
286 10
                case PdfSettings::PRINTER:
287 9
                case PdfSettings::PREPRESS:
288 4
                    return 1200;
289 3
                default:
290 6
                    return 300;
291 3
            }
292
        }
293
294 10
        return intval($value);
295
    }
296
297
    /**
298
     * Set monochrome image resolution
299
     *
300
     * @param int $monoImageResolution
301
     *
302
     * @return $this
303
     */
304 10
    public function setMonoImageResolution($monoImageResolution)
305
    {
306 10
        $this->setArgument(sprintf('-dMonoImageResolution=%s', $monoImageResolution));
307
308 10
        return $this;
309
    }
310
}
311