This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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\CannotEmbedFontPolicy; |
||
11 | use GravityMedia\Ghostscript\Enum\PdfSettings; |
||
12 | |||
13 | /** |
||
14 | * The font distiller parameters trait. |
||
15 | * |
||
16 | * @package GravityMedia\Ghostscript\Device\DistillerParameters |
||
17 | * |
||
18 | * @link http://ghostscript.com/doc/current/Ps2pdf.htm |
||
19 | */ |
||
20 | trait FontTrait |
||
21 | { |
||
22 | /** |
||
23 | * Get argument value |
||
24 | * |
||
25 | * @param string $name |
||
26 | * |
||
27 | * @return null|string |
||
28 | */ |
||
29 | abstract protected function getArgumentValue($name); |
||
30 | |||
31 | /** |
||
32 | * Set argument |
||
33 | * |
||
34 | * @param string $argument |
||
35 | * |
||
36 | * @return $this |
||
37 | */ |
||
38 | abstract protected function setArgument($argument); |
||
39 | |||
40 | /** |
||
41 | * Get PDF settings |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | abstract public function getPdfSettings(); |
||
46 | |||
47 | /** |
||
48 | * Get cannot embed font policy |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | 10 | View Code Duplication | public function getCannotEmbedFontPolicy() |
0 ignored issues
–
show
|
|||
53 | { |
||
54 | 10 | $value = $this->getArgumentValue('-dCannotEmbedFontPolicy'); |
|
55 | 10 | if (null === $value) { |
|
56 | 10 | switch ($this->getPdfSettings()) { |
|
57 | 10 | case PdfSettings::PREPRESS: |
|
58 | 2 | return CannotEmbedFontPolicy::ERROR; |
|
59 | 4 | default: |
|
60 | 8 | return CannotEmbedFontPolicy::WARNING; |
|
61 | 4 | } |
|
62 | } |
||
63 | |||
64 | 10 | return ltrim($value, '/'); |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Set cannot embed font policy |
||
69 | * |
||
70 | * @param string $cannotEmbedFontPolicy |
||
71 | * |
||
72 | * @param \InvalidArgumentException |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | 12 | public function setCannotEmbedFontPolicy($cannotEmbedFontPolicy) |
|
77 | { |
||
78 | 12 | $cannotEmbedFontPolicy = ltrim($cannotEmbedFontPolicy, '/'); |
|
79 | 12 | if (!in_array($cannotEmbedFontPolicy, CannotEmbedFontPolicy::values())) { |
|
80 | 2 | throw new \InvalidArgumentException('Invalid cannot embed font policy argument'); |
|
81 | } |
||
82 | |||
83 | 10 | $this->setArgument(sprintf('-dCannotEmbedFontPolicy=/%s', $cannotEmbedFontPolicy)); |
|
84 | |||
85 | 10 | return $this; |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Whether to embed all fonts |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 10 | public function isEmbedAllFonts() |
|
94 | { |
||
95 | 10 | $value = $this->getArgumentValue('-dEmbedAllFonts'); |
|
96 | 10 | if (null === $value) { |
|
97 | 10 | switch ($this->getPdfSettings()) { |
|
98 | 10 | case PdfSettings::SCREEN: |
|
99 | 2 | return false; |
|
100 | 4 | default: |
|
101 | 8 | return true; |
|
102 | 4 | } |
|
103 | } |
||
104 | |||
105 | 10 | return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * Set embed all fonts flag |
||
110 | * |
||
111 | * @param string $embedAllFonts |
||
112 | * |
||
113 | * @return $this |
||
114 | */ |
||
115 | 10 | public function setEmbedAllFonts($embedAllFonts) |
|
116 | { |
||
117 | 10 | $this->setArgument(sprintf('-dEmbedAllFonts=%s', $embedAllFonts ? 'true' : 'false')); |
|
118 | |||
119 | 10 | return $this; |
|
120 | } |
||
121 | |||
122 | /** |
||
123 | * Get max subset pct |
||
124 | * |
||
125 | * @return int |
||
126 | */ |
||
127 | 2 | public function getMaxSubsetPct() |
|
128 | { |
||
129 | 2 | $value = $this->getArgumentValue('-dMaxSubsetPct'); |
|
130 | 2 | if (null === $value) { |
|
131 | 2 | return 100; |
|
132 | } |
||
133 | |||
134 | 2 | return intval($value); |
|
135 | } |
||
136 | |||
137 | /** |
||
138 | * Set max subset pct |
||
139 | * |
||
140 | * @param int $maxSubsetPct |
||
141 | * |
||
142 | * @return $this |
||
143 | */ |
||
144 | 2 | public function setMaxSubsetPct($maxSubsetPct) |
|
145 | { |
||
146 | 2 | $this->setArgument(sprintf('-dMaxSubsetPct=%s', $maxSubsetPct)); |
|
147 | |||
148 | 2 | return $this; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * Whether to subset fonts |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | 2 | public function isSubsetFonts() |
|
157 | { |
||
158 | 2 | $value = $this->getArgumentValue('-dSubsetFonts'); |
|
159 | 2 | if (null === $value) { |
|
160 | 2 | return true; |
|
161 | } |
||
162 | |||
163 | 2 | return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
164 | } |
||
165 | |||
166 | /** |
||
167 | * Set subset fonts flag |
||
168 | * |
||
169 | * @param bool $subsetFonts |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | 2 | public function setSubsetFonts($subsetFonts) |
|
174 | { |
||
175 | 2 | $this->setArgument(sprintf('-dSubsetFonts=%s', $subsetFonts ? 'true' : 'false')); |
|
176 | |||
177 | 2 | return $this; |
|
178 | } |
||
179 | } |
||
180 |
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.