-
Notifications
You must be signed in to change notification settings - Fork 263
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
PHPLIB-1118: Drop support for PHP 7.2 and 7.3 #1128
Conversation
0416b94
to
3f08b46
Compare
/** @var mixed */ | ||
private $current; | ||
/** @var array|object|null */ | ||
private $current = 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.
Note that rector keeps changing this to private ?object $current = null;
, which is incorrect as the return type of toPHP
depends on the type map provided. @GromNaN is there a way to tell rector about this?
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.
That's not satisfying, but you can assign to a local var to enforce the type.
/** @var array|object $current */
$current = toPHP(...);
$this->current = $current;
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.
It looks like we are using rector with an outdated version of phpstan stubs. https://github.com/phpstan/phpstan-src/blob/1.10.21/resources/functionMap.php#L6735
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.
To disable the problematic rule, add this to rector.php
:
$rectorConfig->skip([
// ...
TypedPropertyFromAssignsRector::class => [
__DIR__ . '/src/Model/BSONIterator.php',
],
@@ -68,7 +68,7 @@ function toJSON(object $document): string | |||
['x' => 10], // Document | |||
], | |||
], | |||
] | |||
], |
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 change is responsible for most of the non-functional diff in this PR: a trailing comma after the last argument in multi-line method calls is now required. This is consistent with the rules already in place for multi-line arrays.
@@ -16,14 +16,12 @@ | |||
|
|||
class PersistableEntry implements Persistable | |||
{ | |||
/** @var ObjectId */ | |||
private $id; | |||
private ObjectId $id; |
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 went through the various type changes and confirmed they were accurate, but a second look certainly won't hurt.
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 to me. Some missing property types from ext-mongodb
, maybe due to outdated stubs.
When types are added to properties, the biggest risk is to have an error when trying to access an uninitialized property.
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.
Note: the missing property types weren't caught by Rector for some reason, and I only later realised that we had an exclusion in the phpcs config to prevent native types from being added. This has since been removed and types for properties are now enforced.
3f08b46
to
14d6d65
Compare
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.
LGTM. With a few optional comments.
src/Operation/CreateIndexes.php
Outdated
return (string) $index; | ||
}, $this->indexes); | ||
return array_map( | ||
fn (IndexInput $index): string => (string) $index, |
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 function is strval
.
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.
Using strval
would remove the type-checking of IndexInput, but I suppose there's not much risk in doing so since we build the array in the constructor.
$a = json_encode($a); | ||
$b = json_encode($b); | ||
$a = json_encode($a, JSON_THROW_ON_ERROR); | ||
$b = json_encode($b, JSON_THROW_ON_ERROR); |
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 improvement. Even if that doesn't change anything for the test.
src/Operation/CreateIndexes.php
Outdated
return (string) $index; | ||
}, $this->indexes); | ||
return array_map( | ||
fn (IndexInput $index): string => (string) $index, |
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.
Using strval
would remove the type-checking of IndexInput, but I suppose there's not much risk in doing so since we build the array in the constructor.
14d6d65
to
6eee5ec
Compare
This uses rector and phpcbf to automatically fix issues
6eee5ec
to
b8acdd1
Compare
b8acdd1
to
17f395a
Compare
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.
LGTM after the necessary change in EntityMap.php
.
Everything else is suggestions, for which I'll defer to you.
*/ | ||
private static $codeNameMap = [ | ||
/** @see https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err */ | ||
private static array $codeNameMap = [ |
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.
Not sure why those weren't addressed, I'll let @GromNaN follow up on this.
PHPLIB-1118
This drops support for PHP 7.2 and 7.3 and updates code for PHP 7.4. Changes have been made automatically using rector and phpcbf. A few manual fixes were applied (a few property types were fixed to exclude
null
).