? Success

User tests: Successful: Unsuccessful:

avatar clinchergt
clinchergt
26 Oct 2014

Simple code clean-up. This shouldn't impact Joomla's behaviour in any way.

Code removed was redundant, as the operator already returns either true or false.

avatar clinchergt clinchergt - open - 26 Oct 2014
avatar jissues-bot jissues-bot - change - 26 Oct 2014
Labels Added: ?
avatar clinchergt
clinchergt - comment - 26 Oct 2014

There's actually quite a few of these. I didn't find anything about them in the coding guidelines, so I'm guessing they aren't purposely coded that way.

avatar Bakual
Bakual - comment - 26 Oct 2014

I agree that this code doesn't make sense as is and your change works of course.
I wonder if we could leave the brackets there. It's not needed from a technical point but imho would increase readability of code. Like this:
self::$mode_sef = ($router->getMode() == JROUTER_MODE_SEF);

What do you think?

avatar joomdonation
joomdonation - comment - 26 Oct 2014

+1 @Bakual. I was thinking the same.

avatar clinchergt
clinchergt - comment - 26 Oct 2014

@Bakual @joomdonation Agreed. I even considered leaving the brackets.

Should this apply for every redundant ternary conditional in the code? I'm gonna go ahead and vote no. There are some instances where it's helpful, like when e.g. a function is called and it's not entirely intuitive that it returns a boolean (like: $foo = bar() ? true : false [and they might not even return booleans] . There are examples like those in the code.

So how about applying this for ternary conditionals that have a conditional operator instead of a function as their condition? Or maybe cast to boolean the result of the function to make it readable and deal with non-boolean results and remove the ternary operator. Thoughts?

avatar Bakual
Bakual - comment - 26 Oct 2014

For functions type casting to boolean should work imho. So $foo = (bool) bar();. For functions which already return a boolean I would just use the return value without type casting.
But maybe that is something which could be discussed in the codestyle repo to get more feedback?

avatar brianteeman brianteeman - change - 28 Oct 2014
Category Code style
avatar Hackwar
Hackwar - comment - 8 Dec 2014

This would be superseded by #5140

avatar clinchergt clinchergt - change - 8 May 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-05-08 22:04:51
Closed_By clinchergt
avatar clinchergt clinchergt - close - 8 May 2015

Add a Comment

Login with GitHub to post a comment