-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Qual: Fix phan notices #32536
base: develop
Are you sure you want to change the base?
Qual: Fix phan notices #32536
Conversation
07154af
to
126581f
Compare
126581f
to
3ba04e7
Compare
@@ -56,14 +61,10 @@ | |||
//$search_xaxis = GETPOST('search_xaxis', 'array'); | |||
if (GETPOST('search_xaxis', 'alpha') && GETPOST('search_xaxis', 'alpha') != '-1') { | |||
$search_xaxis = array(GETPOST('search_xaxis', 'alpha')); | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing this else ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial value is now set earlier so that $search_xaxis
is always initialized for the static analysis and there is no need to repeat this (and avoids getting a notification that the value was already assigned).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the customreport.php page is called as a standalone page (not as an include), i do not see at wich line the $search_xaxis is already initialized.
Can you point where the init is done ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the "else" branch where this value is not set, we have explicitly this comment:
// $search_measures, $search_xaxis or $search_yaxis may have been defined by the parent.
It says 'may be', so the code the follows needs to be protected from unset variables.
We can observe this protection:
dolibarr/htdocs/core/customreports.php
Lines 410 to 413 in 28a9552
} elseif ($mode == 'graph' && isset($search_xaxis) && is_array($search_xaxis) && count($search_xaxis) > 1) { | |
setEventMessages($langs->trans("OnlyOneFieldForXAxisIsPossible"), null, 'warnings'); | |
$search_xaxis = array(0 => $search_xaxis[0]); | |
} |
dolibarr/htdocs/core/customreports.php
Lines 410 to 413 in 28a9552
} elseif ($mode == 'graph' && isset($search_xaxis) && is_array($search_xaxis) && count($search_xaxis) > 1) { | |
setEventMessages($langs->trans("OnlyOneFieldForXAxisIsPossible"), null, 'warnings'); | |
$search_xaxis = array(0 => $search_xaxis[0]); | |
} |
Therefore it is useless to initialize variables to "empty values" that are protected with isset anyway.
In case the protection is unsufficient, the static analysis should kick in and report it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right.
It's true. value can be set by parent when the page is called as an include. So should not be erased in this case.
When called as a standalone page, it may be unnitialized but if there is a protection later, we can avoid it to simplify code.
Will wait CTI green to merge with your removal.
f5ce9d7
to
28a9552
Compare
8d4ccaa
to
e5dba43
Compare
e5dba43
to
a016db1
Compare
a016db1
to
76c5dac
Compare
Qual: Fix phan notices
Fix a set of phan notices.