loading...

re: A simple tip for cleaner code VIEW POST

FULL DISCUSSION
 

What about:

        function foo($bar)
        {
            $value = '';            

            if ($bar > 0) {
                $value = "YES";
            } else if ($bar == 0) {
                $value = "MAYBE"
            } else {
                $value = "NO";
            }



            foo( $value );
            return $value;
        }

The simple addition of foo makes the second form entirely reasonable.

Without knowing the history of the code it's hard to say why it's ended up at the form it currently has. It's way too easy to look at things in isolation and find fault with them, or draw conclusions about what is clean/bad.

 

Please extract the middle part as a separate function and resubmit your pull request ;-p :-).

code of conduct - report abuse