? Success

User tests: Successful: Unsuccessful:

avatar nonumber
nonumber
23 Aug 2014

Cleans up useless uses of else and unnecessary indentation due to 'reverse-logic' in ifs.

So this improves readability of code by trying to eliminate the use of else statements and keeping the indentation to the bare minimum.

For instance, instead of wrapping stuff in multiple 'positive' if checks, simply do 'negative' ifchecks and return early.
This means you don't need to nest if statements.

The same can be done with for/foreach loops, but then do continue in 'negative' if checks.

Also removed else statements if the previous if` block ends with a return, like:

if($something)
{
   doStuff();;

   return $this;
}
else
{
   doOtherStuff();

   return $that;
}

Can be replaced with:

if($something)
{
   doStuff();;

   return $this;
}

doOtherStuff();

return $that;

Testing Instructions

This affects the JInstaller, so test the installer in Joomla.

Just one file?

This is the first file I went through to improve a bit (can of course be improved even more with more effort). If this fares well, I'll do other files too.

Credits

The improvements are based on a few rules from PHP Object Callisthenics. Kudos to @rdohms for inspiring the PHP and Joomla developers with that!

avatar nonumber nonumber - open - 23 Aug 2014
avatar jissues-bot jissues-bot - change - 23 Aug 2014
Status Pending New
Labels Added: ?
avatar nonumber nonumber - change - 23 Aug 2014
The description was changed
avatar n9iels
n9iels - comment - 28 Aug 2014

@test: successful, tested all the ways to install a extension and found no problems.

avatar nonumber
nonumber - comment - 28 Aug 2014

Thanks @n9iels !

avatar brianteeman brianteeman - change - 28 Aug 2014
Status New Pending
avatar nonumber
nonumber - comment - 20 Sep 2014

Been lying around for 4 weeks now. So no interest = close.

avatar nonumber nonumber - close - 20 Sep 2014
avatar nonumber nonumber - change - 20 Sep 2014
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2014-09-20 13:04:49

Add a Comment

Login with GitHub to post a comment