1 | <?php |
||
9 | class Output |
||
10 | { |
||
11 | /** |
||
12 | * The content to be output |
||
13 | * |
||
14 | * @var string $content |
||
15 | */ |
||
16 | protected $content; |
||
17 | |||
18 | /** |
||
19 | * Whether or not to add a new line after the output |
||
20 | * |
||
21 | * @var boolean $new_line |
||
22 | */ |
||
23 | protected $new_line = true; |
||
24 | |||
25 | /** |
||
26 | * The array of available writers |
||
27 | * |
||
28 | * @var array[] $writers |
||
29 | */ |
||
30 | protected $writers = []; |
||
31 | |||
32 | /** |
||
33 | * Default writers when one isn't specifed |
||
34 | * |
||
35 | * @var WriterInterface[] $default |
||
36 | */ |
||
37 | protected $default = []; |
||
38 | |||
39 | /** |
||
40 | * Writers to be used just once |
||
41 | * |
||
42 | * @var null|array $once |
||
43 | */ |
||
44 | protected $once; |
||
45 | |||
46 | 972 | protected $persist = false; |
|
47 | |||
48 | 972 | public function __construct() |
|
56 | |||
57 | /** |
||
58 | 40 | * Dictate that a new line should not be added after the output |
|
59 | */ |
||
60 | 40 | public function sameLine() |
|
66 | |||
67 | /** |
||
68 | * Add a writer to the available writers |
||
69 | * |
||
70 | * @param string $key |
||
71 | * @param WriterInterface|array $writer |
||
72 | * |
||
73 | 972 | * @return \League\CLImate\Util\Output |
|
74 | */ |
||
75 | 972 | public function add($key, $writer) |
|
81 | |||
82 | /** |
||
83 | * Set the default writer |
||
84 | * |
||
85 | 972 | * @param string|array $keys |
|
86 | */ |
||
87 | 972 | public function defaultTo($keys) |
|
91 | |||
92 | /** |
||
93 | * Add a default writer |
||
94 | * |
||
95 | 4 | * @param string|array $keys |
|
96 | */ |
||
97 | 4 | public function addDefault($keys) |
|
101 | |||
102 | /** |
||
103 | * Register a writer to be used just once |
||
104 | * |
||
105 | * @param string|array $keys |
||
106 | * |
||
107 | 8 | * @return \League\CLImate\Util\Output |
|
108 | */ |
||
109 | 8 | public function once($keys) |
|
115 | |||
116 | /** |
||
117 | * Persist or un-persist one time writers (for multi-line output) |
||
118 | * |
||
119 | * @param bool $persist |
||
120 | * |
||
121 | 4 | * @return \League\CLImate\Util\Output |
|
122 | */ |
||
123 | 4 | public function persist($persist = true) |
|
133 | |||
134 | /** |
||
135 | * Get a specific writer |
||
136 | * |
||
137 | * @param string $writer |
||
138 | * |
||
139 | * @return WriterInterface|array |
||
140 | 4 | * @throws UnexpectedValueException if writer key doesn't exist |
|
141 | */ |
||
142 | 4 | public function get($writer) |
|
154 | |||
155 | /** |
||
156 | * Get the currently available writers |
||
157 | * |
||
158 | 4 | * @return array |
|
159 | */ |
||
160 | 4 | public function getAvailable() |
|
170 | |||
171 | /** |
||
172 | * Write the content using the provided writer |
||
173 | * |
||
174 | 80 | * @param string $content |
|
175 | */ |
||
176 | 80 | public function write($content) |
|
188 | |||
189 | /** |
||
190 | * Resolve the writer(s) down to an array of WriterInterface classes |
||
191 | * |
||
192 | * @param WriterInterface|array|string $writer |
||
193 | * |
||
194 | 972 | * @return array |
|
195 | */ |
||
196 | 972 | protected function resolve($writer) |
|
206 | |||
207 | /** |
||
208 | * @param array $writer |
||
209 | * |
||
210 | 972 | * @return array |
|
211 | */ |
||
212 | 972 | protected function resolveArrayWriter($writer) |
|
216 | |||
217 | /** |
||
218 | * @param object $writer |
||
219 | * |
||
220 | 972 | * @return WriterInterface|false |
|
221 | */ |
||
222 | 972 | protected function resolveObjectWriter($writer) |
|
230 | |||
231 | /** |
||
232 | * @param string $writer |
||
233 | * |
||
234 | 12 | * @return array|false |
|
235 | */ |
||
236 | 12 | protected function resolveStringWriter($writer) |
|
244 | |||
245 | /** |
||
246 | * @param mixed $writer |
||
247 | 8 | * @throws InvalidArgumentException For non-valid writer |
|
248 | */ |
||
249 | protected function handleUnknownWriter($writer) |
||
261 | |||
262 | /** |
||
263 | * Get the readable version of the writer(s) |
||
264 | * |
||
265 | * @param array $writer |
||
266 | * |
||
267 | 4 | * @return string|array |
|
268 | */ |
||
269 | 4 | protected function getReadable(array $writer) |
|
279 | |||
280 | /** |
||
281 | * Get the writers based on their keys |
||
282 | * |
||
283 | * @param string|array $keys |
||
284 | * |
||
285 | 972 | * @return array |
|
286 | */ |
||
287 | 972 | protected function getWriters($keys) |
|
293 | |||
294 | /** |
||
295 | 80 | * @return WriterInterface[] |
|
296 | */ |
||
297 | 80 | protected function getCurrentWriters() |
|
301 | |||
302 | /** |
||
303 | 68 | * Reset anything only used for the current content being written |
|
304 | */ |
||
305 | protected function resetOneTimers() |
||
315 | } |
||
316 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.