-
Notifications
You must be signed in to change notification settings - Fork 188
[Core: Config] Add type declarations to function signatures #4127
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
Conversation
php/libraries/NDB_Config.class.inc
Outdated
| 'While attempting to get Subproject config settings, caught ' . | ||
| "DatabaseException: `$e`" | ||
| ); | ||
| return array(); |
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.
This return is unreachable.. but other than that, what's the point of this change?
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'll remove the unreachable return.
I thought it would be better not to silence the DB exception because it probably means something went wrong. Returning null to me makes it seem like there was no entry for $subprojectID in the table -- but in that case there shouldn't be an exception thrown; pselectRow should just return null.
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 that case why not just remove the try/catch? If the database throws an exception and it isn't caught the stack trace will tell you where it came from.
HenriRabalais
left a comment
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.
A few questions
| * @return mixed The value from the database, or null if nothing found. | ||
| */ | ||
| function getSettingFromDB($name, $id=null) | ||
| function getSettingFromDB(string $name, ?int $id = null) |
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.
Given the description in the return doc, couldn't the return type be stated as ?array ?
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 can't remember when I added the FIXME above but no, this can return array, string or null
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 block can be updated to indicate a sum type even if the function signature can't, phan might be able to use the slightly tighter bounds to track down a few more bugs from the doc than "mixed".. but I'll merge this as is, since it's relatively minor.
php/libraries/NDB_Config.class.inc
Outdated
| * @return NDB_Config object | ||
| */ | ||
| static function &singleton($configFile = null) | ||
| static function &singleton(?string $configFile = null) |
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 there a NDB_Config object class that can be declared in the function declared type here? e.g. : \NDB_Config
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.
Yes I think so
php/libraries/NDB_Config.class.inc
Outdated
| * @param string $name The name of the XML node to retrieve. | ||
| * | ||
| * @return string The value from the config.xml | ||
| * @return mixed The value from the config.xml |
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.
instead of mixed, would it be better to state the potential types that can be returned?
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.
Yep!
See #3878 for background