No Code Attached Yet
avatar aDaneInSpain
aDaneInSpain
10 Mar 2023

Example (code added 13 years ago):

$saveOrder = $listOrder == 'a.ordering';

$saveOrder = $listOrder == 'a.ordering';

This is in many files, and I stumbled upon it as I find is very cryptic to read personally.

According to PSR-12 then

The body of each structure MUST be enclosed by braces. This standardizes how the structures look and reduces the likelihood of introducing errors as new lines get added to the body.

I am just curious if this is considered acceptable in the Joomla code base?

If it should be PRS-12 compatible, then I believe that code should be written more ugly but easier to understand:

$saveOrder = false;
if ($listOrder == 'a.ordering' ) {
    $saveOrder = true;
}
avatar aDaneInSpain aDaneInSpain - open - 10 Mar 2023
avatar joomla-cms-bot joomla-cms-bot - change - 10 Mar 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 10 Mar 2023
avatar aDaneInSpain aDaneInSpain - change - 10 Mar 2023
Title
Control structures with no braces is not PSR-12 compatible
Control structures with no braces are not PSR-12 compatible
avatar aDaneInSpain aDaneInSpain - edited - 10 Mar 2023
avatar Fedik
Fedik - comment - 10 Mar 2023

Hi,
If I not mistaken, it a Ternary operator.

$saveOrder = $listOrder == 'a.ordering'; is shorter version of:

$saveOrder = $listOrder == 'a.ordering' ? true : false;

And the quote you posted about Control structures is about to avoid stuff like:

if ($foo)
  $bar = 1;
avatar aDaneInSpain aDaneInSpain - change - 10 Mar 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-03-10 10:14:24
Closed_By aDaneInSpain
avatar aDaneInSpain
aDaneInSpain - comment - 10 Mar 2023

Yeah, Seems like you are right. I had not read this part:

image

avatar aDaneInSpain aDaneInSpain - close - 10 Mar 2023

Add a Comment

Login with GitHub to post a comment