-
Notifications
You must be signed in to change notification settings - Fork 175
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
[Test] Add phpstan tool to test suite and fix detected errors. #4928
Conversation
Forgot to do |
Nice catches! |
@xlecours No I don't think the tool cares. As far as I know |
I usually prefer explicit statements. But in this case, the visibility would need to be set to public, because there might be calls like [TL;DR] leave them |
"public" is better than "var" because it's explicit. The "var" keyword shouldn't be used outside of legacy code. |
There are some phan issues that exist on the Many of these are/will be addressed by #4914 so I'm going to mark this PR as Blocked until that one is merged. |
This PR now includes phpstan in the test suite. I was able to run it at max level and fix all detected errors! Pretty sweet. |
Travis is failing because PHP 7.2 is too old to run the dependencies for this version. Since this is unlikely to go into LORIS 22 anyway, I think I'll punt this until 7.3 is required |
To be rebased onto the "Dev" branch after 22 is released. |
Co-Authored-By: Rida Abou-Haidar <ridz1208@users.noreply.github.com>
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.
Good cleanup. Now we need to fix all those public variables. At least we now have a better idea of how many there are...
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.
mostly looks good except for some minor things
|
||
$formArray = $renderer->toArray(); | ||
} | ||
$formArray = $this->form->toElementArray(); |
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.
What about the other part of the else statement? What is this trying to solve? I think this change of behaviour is likely to break things with different types of instruments
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 believe there was an issue with HTML_QuickForm_Renderer_Array
because it doesn't exist in the code.
I made this PR 6 months ago so I'm not sure about the details.
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 just did a little investigation of the impact of losing this else case and I think it means the API would be broken for the endpoint which gets the instrument in a JSON format for projects that had old instruments that couldn't be updated to LorisForm and were still using QuickForm.
There was only 1 such instrument that I could find when I searched the IBIS repo, and I'm not aware of anyone/thing depending on that endpoint of the API, so I guess it should be fine.
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.
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.
We can add a note in the CHANGELOG about this if it ends up being a breaking change.
Co-Authored-By: Dave MacFarlane <driusan@gmail.com>
@driusan I've incorporated your suggestions. I added a note in the CHANGELOG about QuickForm complications and added the Could you re-review? |
*/ | ||
var $_feedbackThread; | ||
protected $feedbackThread; |
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 doc (@private
) and the code (protected
) here still don't seem to agree.
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.
Thanks, just fixed it above
&& (is_integer($value)); | ||
return intval($value) > 0 | ||
&& strlen($value) <= self::SESSIONID_MAX_LENGTH | ||
&& ctype_digit($value); |
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.
what was wrong with is_integer?
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.
is_int() returns true if the argument is an integer type, ctype_digit() takes a string argument and returns true if all the characters in the string are digits.
The value is passed as a string so is_integer()
always returns false
https://stackoverflow.com/questions/236406/is-there-a-difference-between-is-int-and-ctype-digit
Co-Authored-By: Dave MacFarlane <driusan@gmail.com>
Reverses changes from #4928 that renames $ValidityEnabled to $validityEnabled and $ValidityRequired to $validityRequired. The variabes are UpperCamerCase elsewhere on Loris. This removes the following error that does not allow the Validity flags to render in instruments' control panels PHP Notice: Undefined property: NDB_BVL_Instrument_aosi::$validityEnabled in /var/www/loris/php/libraries/NDB_BVL_InstrumentStatus_ControlPanel.class.inc on line 101 PHP Notice: Undefined property: NDB_BVL_Instrument_aosi::$validityRequired in /var/www/loris/php/libraries/NDB_BVL_InstrumentStatus_ControlPanel.class.inc on line 102
Brief summary of changes
I found a cool static analysis tool called PHP Stan which is like
phan
but much faster and flags additional issues.This PR cleans up some of the errors it flags.
I'm going to add another commit that adds phpstan as a dependency but it requires PHPUnit >= 7 to work properly. This should be solved by #4433 so I'm marking this PR as blocked for now.