Check the logic in the Shell::in($prompt, $options = null, $default = null) #411

merged 4 commits into from Jan 18, 2012


None yet

2 participants

fitorec commented Jan 16, 2012

Reviewing the code of the Shell I found a logic statement in particular that made ​​me confuzed, to which we apply a simple reduction:

If we review the logic of the following code:

     while ($in === '' || ($in !== '' && (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options)) && !in_array($in, $options))) 

We will realize that $in must be different of '', which indicates that the code is equivalent to

     while ($in === '' || (!in_array(strtolower($in), $options) && !in_array(strtoupper($in), $options) && !in_array($in, $options)) 

Finally, the logic is: (!a && !b && !c) may take the form: !(a || b || c):

      while ($in === '' || !(in_array(strtolower($in), $options) || in_array(strtoupper($in), $options) || in_array($in, $options))) {



The logic could be simplified even more if $options was pre-seeded with the various casings. Something like:

$options = array_merge(
   array_map('strtolower', $options),
   array_may('strtoupper', $options)

Then the changed lines could just be in_array($in, $options).

@markstory markstory merged commit e080bb2 into cakephp:2.0 Jan 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment