-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add built-in return types #5367
base: master
Are you sure you want to change the base?
Conversation
a8c34b5
to
d3794a5
Compare
d3794a5
to
73ec887
Compare
*/ | ||
public function getUnit(): string { | ||
public function getUnit() { |
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 is a manual fix where Rector didn't understand that a subclass (SMWQuantityValue
) can return bool here.
I did not review the code to see if it's just a theorerical issue (i.e. perhaps it's bool initially but always changes to a string). The class member m_mainunit
is typed as string|bool
.
*/ | ||
protected function getServiceLinkParams(): bool { | ||
protected function getServiceLinkParams() { |
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 is a manual fix where Rector didn't understand that the subclasses return arrays.
Fixed. |
@@ -164,7 +164,10 @@ public function getColumnList( array $dataItems, $colsThreshold = 10 ) { | |||
return $htmlColumns->getHtml(); | |||
} | |||
|
|||
private function buildList( $dataItems ) { | |||
/** | |||
* @return array<int|string, mixed[]> |
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 is an example of the automatically added array type. If this kind of documentation is pointless (albeit required for the CS tools) then I can rather remove these now. If somebody looks at this code later and comes up with a better type we can add it then.
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 one does not seem super helpful. I'm also concerned correctness. If Rector is taking info from existing info in docs, then it might amplify mistakes in those docs. I do not trust type docs in SMW as I've seen them be wrong multiple times in the past.
4f32543
to
736c19d
Compare
@@ -47,7 +47,10 @@ public function get( $key ) { | |||
return $this->{$key}( $this->store->getConnection( 'mw.db' ) ); | |||
} | |||
|
|||
private function loadFromDB( $connection ) { | |||
/** | |||
* @return array{total_row_count: mixed, last_id: mixed, duplicate_count: int, rows: array{rev_count: mixed, smw_namespace_group_by_count: mixed, smw_iw: array{delete_count: mixed, redirect_count: mixed}, smw_proptable_hash: array{query_match_count: mixed, query_null_count: mixed}}}[]|array{total_row_count: mixed, rows: array{active_links_count: mixed, invalid_links_count: mixed, unassigned_count: mixed}}[]|array{total_row_count: mixed, unique_terms_occurrence_in_percent: int|float, rows: array{blob_field_null_row_count: mixed, terms_occurrence: array{single_occurrence_total_count: mixed, multi_occurrence_total_count: mixed}}}[]|array{query_time: float, snapshot_date: string}[] |
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.
Spam?
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.
Possibly yes
@@ -143,7 +143,10 @@ protected function doUpdateTable( $tableName, array $attributes = null ) { | |||
} | |||
} | |||
|
|||
private function getCurrentFields( $tableName ) { | |||
/** | |||
* @return string[]|string[][] |
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 is wrong, but is strictly correct because $row->Type
could be an array and str_replace
can run on an array, hence why it thinks you can have 2D array.
@@ -759,7 +759,7 @@ public function getHash() { | |||
* | |||
* @return boolean | |||
*/ | |||
public function isNumeric() { | |||
public function isNumeric(): bool { |
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.
Return type narrowing to base classes or interfaces that are extended in other extensions require a major release. For this particular class, possibly Maps is the only affected extension, with its Geo DataValue.
Changes to ResultPrinter will have a wider impact
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 always make a pragmatic exception to the rule, but would need to asses the impact of doing so. Or we could bump to 5.x.
Either way, probably good to first do #5366 before merging potentially disruptive changes.
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 do you suggest? Should we aim for a new major version in the short term, or is adding types like this too much effort? Otherwise I'll rather focus on missing types throwing deprecation notices in PHP 8.1 (e.g. #5370). But I suppose there is still a chance that by adding a missing type there we might still cause narrowing. I'm not familiar with all the downstream extensions, so that makes it a bit difficult to test.
edit: I missed your second comment. Yes, doing #5366 first sounds like a good idea. If we end up bumping to 5.x we should probably also review the minimum PHP version.
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 should definitely throw out 7.3, maybe also 7.4.
New major version in the short term seems fine to me, but would still do a patch/minor release first.
Refs #5368
Done with Rector. This required multiple runs and some manual fixes where SMW was too ambiguous. My understanding is the more return types you have, the better it is able to infer additional missing types.
There are still cases where built-in types are missing, however in the current state Rector no longer adds anything for me, even after clearing Rector's cache. That might be due to ambiguity, or I suspect I need to use additional Rector rules, but I will try them in follow-up PRs.
The array return type refactoring adds comments documenting the array contents. I did not manually touch or review any of those additions.
This PR can be squashed. I did separate commits to make the reruns/manual fixes clearer for myself.
Rector config: