@@ -247,12 +247,11 @@ optionally accepts a value, but it's a bit tricky. Consider this example::
247247 )
248248 ;
249249
250- This option can be used in 3 ways: ``greet --yell ``, ``greet yell=louder ``,
251- and ``greet ``. However, it's hard to distinguish between passing the option
250+ This option can be used in 3 ways: ``greet --yell ``, ``greet yell=louder ``,
251+ and ``greet ``. However, it's hard to distinguish between passing the option
252252without a value (``greet --yell ``) and not passing the option (``greet ``).
253253
254- To solve this issue, you have to set the option's default value to
255- ``false ``::
254+ To solve this issue, you have to set the option's default value to ``false ``::
256255
257256 // ...
258257 use Symfony\Component\Console\Input\InputOption;
@@ -268,32 +267,31 @@ To solve this issue, you have to set the option's default value to
268267 )
269268 ;
270269
271- The input will now return the default value for the option when it is not
272- specified (``greet ``), a null value when it is specified but not explicitly
273- defined (``greet --yell ``), and the defined value when defined
274- (``greet --yell=lounder ``). Now check the value of the option::
270+ Now it's possible to differentiate between not passing the option and not
271+ passing any value for it::
275272
276273 $optionValue = $input->getOption('yell');
277- if ($optionValue === false ) {
278- // option was not specified
274+ if (false === $optionValue ) {
275+ // in this case, the option was not passed when running the command
279276 $yell = false;
280- $yellLouder = false;
281- } elseif ($optionValue === null) {
282- // option was specified but no value given
277+ $yellLouder = false;
278+ } elseif (null === $optionValue) {
279+ // in this case, the option was passed when running the command
280+ // but no value was given to it
283281 $yell = true;
284- $yellLouder = false;
282+ $yellLouder = false;
285283 } else {
286- // option was specified with a value which is now stored in $optionValue
284+ // in this case, the option was passed when running the command and
285+ // some specific value was given to it
287286 $yell = true;
288- if ($optionValue === 'louder' ) {
289- $yellLouder = true;
287+ if ('louder' === $optionValue ) {
288+ $yellLouder = true;
290289 } else {
291- $yellLouder = false;
290+ $yellLouder = false;
292291 }
293292 }
294293
295- Once you are clear on how the default value is implemented you could consense the
296- above code into less lines of code since ``false !== null ``::
294+ The above code can be simplified as follows because ``false !== null ``::
297295
298296 $optionValue = $input->getOption('yell');
299297 $yell = ($optionValue !== false);
0 commit comments