Skip to content

Simplify some ternary operations using elvis operator and remove unnecessary parentheses in libraries/legacy#13240

Merged
rdeutz merged 9 commits intojoomla:stagingfrom
frankmayer:elvis-and-unneeded-parentheses-in-libraries-legacy
Jun 13, 2017
Merged

Simplify some ternary operations using elvis operator and remove unnecessary parentheses in libraries/legacy#13240
rdeutz merged 9 commits intojoomla:stagingfrom
frankmayer:elvis-and-unneeded-parentheses-in-libraries-legacy

Conversation

@frankmayer
Copy link
Copy Markdown
Contributor

@frankmayer frankmayer commented Dec 15, 2016

Summary of Changes

  • Simplify some ternary operations using elvis operator and remove unnecessary parentheses in libraries/legacy

This PR is part of a set to try to separate some of the changes done in one of my previous batch PR's for the libraries/legacy directory, which is still on hold (#12220).
Once the new set is merged it will hopefully reduce the changes in that PR, so it can be reviewed easier and finally be merged.

The changes in this PR should be fairly easy to review. In hope that this will get merged quickly. ;)

Testing Instructions

None, should not change behavior

Documentation Changes Required

None.

@frankmayer frankmayer changed the title Simplify some ternary operations using elvis operator and remove unnecessary parentheses in libraries/cms Simplify some ternary operations using elvis operator and remove unnecessary parentheses in libraries/legacy Dec 16, 2016
@frankmayer frankmayer mentioned this pull request Jan 6, 2017
3 tasks
…es-legacy

# Conflicts:
#	libraries/legacy/model/legacy.php
@frankmayer
Copy link
Copy Markdown
Contributor Author

Conflicts resolved. Pls check and merge.

@@ -103,10 +103,10 @@ public function __construct($options)
$this->_table = $options['table'];
$this->_field = (isset($options['field']) && $options['field']) ? $options['field'] : 'catid';
$this->_key = (isset($options['key']) && $options['key']) ? $options['key'] : 'id';
Copy link
Copy Markdown
Contributor

@Quy Quy May 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove parentheses in lines 104 and 105.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, in these cases, you can't just simplify it. Since you need the isset() to make sure the value is set... And if simplifying the ternary with the result of (isset($options['field']) && $options['field']) you get a 1 in case of true, not the value of $options['field']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this: $this->_field = isset($options['field']) && $options['field'] ? $options['field'] : 'catid';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you meant removal of parentheses... 😄 I was reading it like simplifying the ternary operation...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I updated the comment after my initial posting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will you remove the parenthesis then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrepereiradasilva LOL, yes...

}

if (($cur_state != $new_state) && $new_state !== null && ($resetPage))
if (($cur_state != $new_state) && $new_state !== null && $resetPage)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove parentheses ($cur_state != $new_state).

$options = array(
'defaultgroup' => ($group) ? $group : (isset($this->option) ? $this->option : JFactory::getApplication()->input->get('option')),
'cachebase' => ($client_id) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache'),
'defaultgroup' => $group ?: (isset($this->option) ? $this->option : JFactory::getApplication()->input->get('option')),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align =>. (Sorry I missed these before 😦 )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are many such cases in lots of files, but lets do those in another PR...
I'll do the ones you have mentioned already, but lets try to get this RTC ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that there might already be another PR for those cases. If not, we can do that in new ones.

public function delete($pk = null)
{
$k = $this->_tbl_key;
$pk = (is_null($pk)) ? $this->$k : $pk;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jun 1, 2017

I have tested this item ✅ successfully on 99ec6fc


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13240.

1 similar comment
@andrepereiradasilva
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 99ec6fc


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13240.

@ghost
Copy link
Copy Markdown

ghost commented Jun 1, 2017

RTC after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jun 1, 2017
@rdeutz rdeutz merged commit c61c407 into joomla:staging Jun 13, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jun 13, 2017
@rdeutz rdeutz added this to the Joomla 3.7.3 milestone Jun 13, 2017
@frankmayer frankmayer deleted the elvis-and-unneeded-parentheses-in-libraries-legacy branch June 13, 2017 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants