Skip to content
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

Merged
merged 11 commits into from
Jul 14, 2023

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jul 13, 2023

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).

@alcaeus alcaeus force-pushed the phplib-1118-drop-old-php branch 3 times, most recently from 0416b94 to 3f08b46 Compare July 13, 2023 12:28
/** @var mixed */
private $current;
/** @var array|object|null */
private $current = null;
Copy link
Member Author

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?

Copy link
Member

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;

Copy link
Member

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

Copy link
Member

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
],
],
]
],
Copy link
Member Author

@alcaeus alcaeus Jul 13, 2023

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;
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

@alcaeus alcaeus requested review from GromNaN and jmikola July 13, 2023 13:13
@alcaeus alcaeus marked this pull request as ready for review July 13, 2023 13:13
Copy link
Member

@GromNaN GromNaN left a 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/Collection.php Outdated Show resolved Hide resolved
src/Database.php Outdated Show resolved Hide resolved
return (string) $index;
}, $this->indexes);
return array_map(
fn (IndexInput $index): string => (string) $index,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is strval.

Copy link
Member

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.

src/Operation/ListCollectionNames.php Outdated Show resolved Hide resolved
$a = json_encode($a);
$b = json_encode($b);
$a = json_encode($a, JSON_THROW_ON_ERROR);
$b = json_encode($b, JSON_THROW_ON_ERROR);
Copy link
Member

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.

tests/UnifiedSpecTests/UnifiedTestRunner.php Show resolved Hide resolved
src/Collection.php Outdated Show resolved Hide resolved
src/Database.php Outdated Show resolved Hide resolved
src/GridFS/Bucket.php Outdated Show resolved Hide resolved
src/MapReduceResult.php Show resolved Hide resolved
return (string) $index;
}, $this->indexes);
return array_map(
fn (IndexInput $index): string => (string) $index,
Copy link
Member

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.

tests/SpecTests/Operation.php Outdated Show resolved Hide resolved
tests/SpecTests/RetryableReadsSpecTest.php Outdated Show resolved Hide resolved
tests/SpecTests/RetryableWritesSpecTest.php Outdated Show resolved Hide resolved
tests/UnifiedSpecTests/RunOnRequirement.php Outdated Show resolved Hide resolved
tests/UnifiedSpecTests/UnifiedTestCase.php Show resolved Hide resolved
@alcaeus alcaeus requested a review from jmikola July 14, 2023 08:52
Copy link
Member

@jmikola jmikola left a 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.

tests/SpecTests/RetryableWritesSpecTest.php Outdated Show resolved Hide resolved
src/Operation/Aggregate.php Show resolved Hide resolved
src/Operation/InsertMany.php Outdated Show resolved Hide resolved
*/
private static $codeNameMap = [
/** @see https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err */
private static array $codeNameMap = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that the private static constants under tests/ were never addressed in c0738eb. Not sure if that was intentional on @GromNaN's part, but I don't remember it coming up in the PR.

Copy link
Member Author

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.

tests/SpecTests/ErrorExpectation.php Outdated Show resolved Hide resolved
tests/UnifiedSpecTests/EntityMap.php Outdated Show resolved Hide resolved
@alcaeus alcaeus merged commit f81b4a6 into mongodb:master Jul 14, 2023
@alcaeus alcaeus deleted the phplib-1118-drop-old-php branch July 14, 2023 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants