Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed redundant if statement #1291

Merged
merged 1 commit into from
Mar 27, 2021

Conversation

Sekiphp
Copy link
Contributor

@Sekiphp Sekiphp commented Oct 30, 2020

Description (*)

In method addIdFilter is redundant if statement and some code is unreachable.

Look at pseudocode below (#3 is never executed because we evalueate if (empty($productId)) { above).

function addIdFilter($productId, $exclude = false)
{
    if (empty($productId)) {
        return "#1 (empty)";
    }
    if (is_array($productId)) {
        if (!empty($productId)) {
            return "#2 (not empty)";
        } else {
            return "#3 (empty)";
        }
    } else {
        return "#4 (not array)";
    }
}


var_dump(addIdFilter(123));             // string(14) "#4 (not array)"
var_dump(addIdFilter([123]));           // string(14) "#2 (not empty)"
var_dump(addIdFilter([0]));             // string(14) "#2 (not empty)"
var_dump(addIdFilter(0));               // string(10) "#1 (empty)"
var_dump(addIdFilter(null));            // string(10) "#1 (empty)"
var_dump(addIdFilter(""));              // string(10) "#1 (empty)"
var_dump(addIdFilter("567"));           // string(14) "#4 (not array)"
var_dump(addIdFilter([null]));          // string(14) "#2 (not empty)"
var_dump(addIdFilter(['']));            // string(14) "#2 (not empty)"
var_dump(addIdFilter(array()));         // string(10) "#1 (empty)"

Manual testing scenarios (*)

$collection = Mage::getModel('catalog/product')->getCollection()->addIdFilter([10, 20, 30]);
var_dump($collection->getColumnValues('sku'));

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Catalog Relates to Mage_Catalog label Oct 30, 2020
Copy link
Contributor

@kiatng kiatng left a comment

Choose a reason for hiding this comment

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

LGTM

@kkrieger85 kkrieger85 added hacktoberfest easy to solve issues for https://hacktoberfest.digitalocean.com/ participant (and everyone else) hacktoberfest-accepted labels Oct 30, 2020
@Flyingmana Flyingmana merged commit 96e8e90 into OpenMage:1.9.4.x Mar 27, 2021
@github-actions
Copy link
Contributor

Unit Test Results

1 files  1 suites   0s ⏱️
0 tests 0 ✔️ 0 💤 0 ❌
2 runs  2 ✔️ 0 💤 0 ❌

Results for commit 96e8e90.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Relates to Mage_Catalog enhancement hacktoberfest easy to solve issues for https://hacktoberfest.digitalocean.com/ participant (and everyone else) hacktoberfest-accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants