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 | /* |
||
4 | * This file is part of the webmozart/console package. |
||
5 | * |
||
6 | * (c) Bernhard Schussek <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Webmozart\Console\UI\Style; |
||
13 | |||
14 | use Webmozart\Assert\Assert; |
||
15 | use Webmozart\Console\Api\Formatter\Style; |
||
16 | |||
17 | /** |
||
18 | * Defines the style of a {@link Grid}. |
||
19 | * |
||
20 | * @since 1.0 |
||
21 | * |
||
22 | * @author Bernhard Schussek <[email protected]> |
||
23 | */ |
||
24 | class GridStyle |
||
25 | { |
||
26 | /** |
||
27 | * @var GridStyle |
||
28 | */ |
||
29 | private static $borderless; |
||
30 | |||
31 | /** |
||
32 | * @var GridStyle |
||
33 | */ |
||
34 | private static $asciiBorder; |
||
35 | |||
36 | /** |
||
37 | * @var GridStyle |
||
38 | */ |
||
39 | private static $solidBorder; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $paddingChar = ' '; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | private $cellFormat = '%s'; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | private $cellAlignment = Alignment::LEFT; |
||
55 | |||
56 | /** |
||
57 | * @var BorderStyle |
||
58 | */ |
||
59 | private $borderStyle; |
||
60 | |||
61 | /** |
||
62 | * @var Style |
||
63 | */ |
||
64 | private $cellStyle; |
||
65 | |||
66 | /** |
||
67 | * A borderless style. |
||
68 | * |
||
69 | * @return GridStyle The style. |
||
70 | */ |
||
71 | 1 | public static function borderless() |
|
72 | { |
||
73 | 1 | if (!self::$borderless) { |
|
74 | 1 | self::$borderless = new static(); |
|
75 | 1 | self::$borderless->borderStyle = BorderStyle::none(); |
|
76 | } |
||
77 | |||
78 | 1 | return clone self::$borderless; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * A style that uses ASCII characters for drawing borders. |
||
83 | * |
||
84 | * @return GridStyle The style. |
||
85 | */ |
||
86 | 9 | View Code Duplication | public static function asciiBorder() |
0 ignored issues
–
show
|
|||
87 | { |
||
88 | 9 | if (!self::$asciiBorder) { |
|
89 | 1 | self::$asciiBorder = new static(); |
|
90 | 1 | self::$asciiBorder->cellFormat = ' %s '; |
|
91 | 1 | self::$asciiBorder->borderStyle = BorderStyle::ascii(); |
|
92 | } |
||
93 | |||
94 | 9 | return clone self::$asciiBorder; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * A style that uses Unicode characters for drawing solid borders. |
||
99 | * |
||
100 | * @return GridStyle The style. |
||
101 | */ |
||
102 | 1 | View Code Duplication | public static function solidBorder() |
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. ![]() |
|||
103 | { |
||
104 | 1 | if (!self::$solidBorder) { |
|
105 | 1 | self::$solidBorder = new static(); |
|
106 | 1 | self::$solidBorder->cellFormat = ' %s '; |
|
107 | 1 | self::$solidBorder->borderStyle = BorderStyle::solid(); |
|
108 | } |
||
109 | |||
110 | 1 | return clone self::$solidBorder; |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * Returns the character used to pad cells to the desired width. |
||
115 | * |
||
116 | * @return string The padding character. |
||
117 | */ |
||
118 | 10 | public function getPaddingChar() |
|
119 | { |
||
120 | 10 | return $this->paddingChar; |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * Sets the character used to pad cells to the desired width. |
||
125 | * |
||
126 | * @param string $char The padding character. |
||
127 | * |
||
128 | * @return static The current instance. |
||
129 | */ |
||
130 | public function setPaddingChar($char) |
||
131 | { |
||
132 | $this->paddingChar = $char; |
||
133 | |||
134 | return $this; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Returns the format string for rendering cells. |
||
139 | * |
||
140 | * @return string The format string. The string contains the substring "%s" |
||
141 | * where the cell content is inserted. |
||
142 | */ |
||
143 | 10 | public function getCellFormat() |
|
144 | { |
||
145 | 10 | return $this->cellFormat; |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * Sets the format string for rendering cells. |
||
150 | * |
||
151 | * @param string $format The format string. The string should contain the |
||
152 | * substring "%s" where the cell content is inserted. |
||
153 | * |
||
154 | * @return static The current instance. |
||
155 | */ |
||
156 | public function setCellFormat($format) |
||
157 | { |
||
158 | $this->cellFormat = $format; |
||
159 | |||
160 | return $this; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Returns the cell alignment. |
||
165 | * |
||
166 | * @return int One of the {@link Alignment} constants. |
||
167 | */ |
||
168 | 10 | public function getCellAlignment() |
|
169 | { |
||
170 | 10 | return $this->cellAlignment; |
|
171 | } |
||
172 | |||
173 | /** |
||
174 | * Sets the cell alignment. |
||
175 | * |
||
176 | * @param int $alignment One of the {@link Alignment} constants. |
||
177 | * |
||
178 | * @return static The current instance. |
||
179 | */ |
||
180 | 2 | public function setCellAlignment($alignment) |
|
181 | { |
||
182 | 2 | Assert::oneOf($alignment, Alignment::all(), 'The cell alignment must be one of the Alignment constants. Got: %s'); |
|
183 | |||
184 | 2 | $this->cellAlignment = $alignment; |
|
185 | |||
186 | 2 | return $this; |
|
187 | } |
||
188 | |||
189 | /** |
||
190 | * Returns the border style. |
||
191 | * |
||
192 | * @return BorderStyle The border style. |
||
193 | */ |
||
194 | 10 | public function getBorderStyle() |
|
195 | { |
||
196 | 10 | return $this->borderStyle; |
|
197 | } |
||
198 | |||
199 | /** |
||
200 | * Sets the border style. |
||
201 | * |
||
202 | * @param BorderStyle $borderStyle The border style. |
||
203 | * |
||
204 | * @return static The current instance. |
||
205 | */ |
||
206 | public function setBorderStyle(BorderStyle $borderStyle) |
||
207 | { |
||
208 | $this->borderStyle = $borderStyle; |
||
209 | |||
210 | return $this; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Returns the style of the grid cells. |
||
215 | * |
||
216 | * @return Style The cell style. |
||
217 | */ |
||
218 | 10 | public function getCellStyle() |
|
219 | { |
||
220 | 10 | return $this->cellStyle; |
|
221 | } |
||
222 | |||
223 | /** |
||
224 | * Sets the style of the grid cells. |
||
225 | * |
||
226 | * @param Style $style The cell style. |
||
227 | * |
||
228 | * @return static The current instance. |
||
229 | */ |
||
230 | public function setCellStyle(Style $style) |
||
231 | { |
||
232 | $this->cellStyle = $style; |
||
233 | |||
234 | return $this; |
||
235 | } |
||
236 | } |
||
237 |
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.