1 | <?php |
||
41 | class HelpMessage |
||
42 | { |
||
43 | /** |
||
44 | * The message which is usually generated by the constructor. |
||
45 | * @var string |
||
46 | */ |
||
47 | private $message = ''; |
||
48 | |||
49 | /** |
||
50 | * The constructor for the HelpMessage class. This constructor does the work |
||
51 | * of generating the help message. This means that nothing can be done to |
||
52 | * change the help message after the class has been instantiated. |
||
53 | * |
||
54 | * @param array $params An associative array which contains the details needed |
||
55 | * to help generate the help message.s |
||
56 | */ |
||
57 | 8 | public function __construct($params) |
|
76 | |||
77 | /** |
||
78 | * The method runs through all the commands and generates formatted lines |
||
79 | * of text to be used as the help message for each commands. |
||
80 | * |
||
81 | * @param array $commands An array of associative arrays with infomation |
||
82 | * about all commands configured into ClearIce. |
||
83 | * @return array |
||
84 | */ |
||
85 | 1 | private function getCommandsHelp($commands) |
|
95 | |||
96 | /** |
||
97 | * The method runs through all the commands and generates formatted lines |
||
98 | * of text to be used as the help message each option. |
||
99 | * |
||
100 | * @param array $options An array of associative arrays with infomation |
||
101 | * about all options configured into ClearIce. |
||
102 | * @param string $command All options returned would belong to the command |
||
103 | * stated in this argument. |
||
104 | * @param string $title A descriptive title for the header of this set |
||
105 | * of options. |
||
106 | * @return array |
||
107 | */ |
||
108 | 8 | private function getOptionsHelp($options, $groups, $command = '', $title = 'Options:') |
|
128 | |||
129 | /** |
||
130 | * Formats the help line of a value which is accepted by an option. If a |
||
131 | * value type is provided in the option, it is used if not it uses a generic |
||
132 | * "VALUE" to show that an option can accept a value. |
||
133 | * |
||
134 | * @param array $option |
||
135 | * @return string |
||
136 | */ |
||
137 | 8 | private function formatValue($option) |
|
144 | |||
145 | /** |
||
146 | * Formats the argument parts of the help line. If an option has both a long |
||
147 | * and a short form both forms are put together, if it has either a short or |
||
148 | * a long form, the respective form is formatted. The formatting includes |
||
149 | * placing a comma between the two forms and padding the output with the |
||
150 | * appropriate spaces. |
||
151 | * |
||
152 | * @param array $option |
||
153 | * @return string |
||
154 | */ |
||
155 | 8 | private function formatArgument($option) |
|
178 | |||
179 | /** |
||
180 | * Wraps the help message arround the argument by producing two different |
||
181 | * columns. The argument is placed in the first column and the help message |
||
182 | * is placed in the second column. |
||
183 | * |
||
184 | * @param string $argumentPart |
||
185 | * @param string $help |
||
186 | * @param integer $minSize |
||
187 | * @return array |
||
188 | */ |
||
189 | 8 | private function wrapHelp($argumentPart, &$help, $minSize = 29) |
|
200 | |||
201 | /** |
||
202 | * Format the help message for an option. This would involve generating a |
||
203 | * sring with your option and and wrapping the help message around it. |
||
204 | * |
||
205 | * @param type $option |
||
206 | * @return string |
||
207 | */ |
||
208 | 8 | private function formatOptionHelp($option) |
|
222 | |||
223 | /** |
||
224 | * Format the help message for a command. This would involve wrapping the |
||
225 | * help message for a given command around the command. |
||
226 | * |
||
227 | * @param type $command |
||
228 | * @return string |
||
229 | */ |
||
230 | 1 | private function formatCommandHelp($command) |
|
241 | |||
242 | 8 | private function getDescriptionMessage(array $params, array &$sections, $section) |
|
248 | |||
249 | 8 | private function getOptionsMessage(array $params, array &$sections) |
|
276 | |||
277 | |||
278 | /** |
||
279 | * Returns the usage message for either the command or the main script |
||
280 | * depending on the state in which the HelpMessage class currently is. |
||
281 | * |
||
282 | * @global array $argv The arguments passed to the |
||
283 | * @param array $params A copy of the parameters passed to the HelpMessage class |
||
284 | */ |
||
285 | 8 | private function getUsageMessage(array $params, array &$sections) |
|
326 | |||
327 | /** |
||
328 | * Returns the message as a string. |
||
329 | * @return string |
||
330 | */ |
||
331 | 8 | public function __toString() |
|
335 | } |
||
336 | |||
337 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: