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

Drop support for PHP 7.4 #2515

Merged
merged 7 commits into from
Mar 28, 2023
Merged

Drop support for PHP 7.4 #2515

merged 7 commits into from
Mar 28, 2023

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Mar 24, 2023

Q A
Type improvement
BC Break no
Fixed issues

Summary

This PR drops support for PHP 7.4. This is mainly required due to the aggregation pipeline builder needing to enforce static types which cannot be worked around (see #2514).

Contained in this PR is a commit that also enforces PHP 8.0 syntax in phpcs. All changes were made using phpcbf and should be safe, but I can drop the commit if we want to defer this to a later PR.

Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

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

Changes in phpstan-baseline.neon are worrying me

/** @var string|null */
public $name;

/** @param string|string[] $value */
public function __construct($value, ?string $name = null)
public function __construct(public $value, ?string $name = null)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why $name wasn't promoted as well

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 assume because the property did not have a type associated with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

since the class is final, I guess we could add types to these properties? A user might have set these properties to another type, but I guess it wouldn't work

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, the type is wrong: $name can be a string or list of strings, and the AnnotationDriver always converts it to an array. I've removed the parameter type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correction: $value is what I was talking about, $name is indeed a string. I've re-added the correct type.

?string $repositoryClass = null,
array $indexes = [],
bool $readOnly = false,
?string $shardKey = null,
$writeConcern = null
public $writeConcern = null,
Copy link
Member

Choose a reason for hiding this comment

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

maybe a bug in PHPCSFixer? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, a result of phpcs requiring a trailing comma for multi-line method declarations.

Copy link
Member

Choose a reason for hiding this comment

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

Poor communication is on me, this was meant to follow previous comment on promoting only some properties instead of all 👼

@@ -234,7 +233,7 @@ public function prepareUpdateData($document)
*/
public function prepareUpsertData($document)
Copy link
Member

Choose a reason for hiding this comment

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

Just a note: we should revisit adding object typehint. For instance here the builder is marked as @internal so we're free to break inheritance here according to our rules

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, absolutely. I'd do so in a separate pull request.

@alcaeus
Copy link
Member Author

alcaeus commented Mar 24, 2023

Changes in phpstan-baseline.neon are worrying me

They look a lot less dramatic once we ignore whitespace changes. Here's the output I had before regenerating the baseline:

 ------ ------------------------------------------------------------------------------------------------------------------ 
  Line   lib/Doctrine/ODM/MongoDB/UnitOfWork.php                                                                           
 ------ ------------------------------------------------------------------------------------------------------------------ 
  1955   Unable to resolve the template type T in call to method Doctrine\ODM\MongoDB\DocumentManager::getClassMetadata()  
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type                            
 ------ ------------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------------------------------------------ 
  Line   lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php                                                        
 ------ ------------------------------------------------------------------------------------------------------------------ 
  165    Unable to resolve the template type T in call to method Doctrine\ODM\MongoDB\DocumentManager::getClassMetadata()  
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type                            
  193    Unable to resolve the template type T in call to method Doctrine\ODM\MongoDB\DocumentManager::getClassMetadata()  
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type                            
  221    Unable to resolve the template type T in call to method Doctrine\ODM\MongoDB\DocumentManager::getClassMetadata()  
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type                            
 ------ ------------------------------------------------------------------------------------------------------------------ 

@alcaeus alcaeus requested a review from malarzm March 24, 2023 13:51
@alcaeus alcaeus force-pushed the drop-php-7.4 branch 2 times, most recently from 7554ff5 to e7752c6 Compare March 24, 2023 14:45
/**
* @param array<string, mixed> $pipeline
* @param array<string, mixed> $options
* @psalm-param PipelineExpression $pipeline
*/
public function __construct(DocumentManager $dm, ?ClassMetadata $classMetadata, Collection $collection, array $pipeline, array $options = [], bool $rewindable = true)
public function __construct(private DocumentManager $dm, private ?ClassMetadata $classMetadata, private Collection $collection, array $pipeline, private array $options = [], private bool $rewindable = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It has been merged and released, so updating slevomat/coding-standard and running phpcbf should fix this and other files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/UnionWith.php Outdated Show resolved Hide resolved
private bool $disableException = false;

/** @param mixed $identifier */
public function __construct(object $document, DocumentManager $dm, $identifier)
public function __construct(object $document, DocumentManager $dm, private $identifier)
Copy link
Contributor

Choose a reason for hiding this comment

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

note for another PR, we can add mixed types

/** @var string|null */
public $name;

/** @param string|string[] $value */
public function __construct($value, ?string $name = null)
public function __construct(public $value, ?string $name = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

since the class is final, I guess we could add types to these properties? A user might have set these properties to another type, but I guess it wouldn't work

lib/Doctrine/ODM/MongoDB/SchemaManager.php Outdated Show resolved Hide resolved
Copy link
Contributor

@franmomu franmomu left a comment

Choose a reason for hiding this comment

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

I'll try to take a look at phpstan if I find some time

lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php Outdated Show resolved Hide resolved
@alcaeus alcaeus merged commit e235642 into doctrine:2.6.x Mar 28, 2023
@alcaeus alcaeus deleted the drop-php-7.4 branch March 28, 2023 09:15
@franmomu franmomu mentioned this pull request Apr 5, 2023
notrix pushed a commit to notrix/mongodb-odm that referenced this pull request Apr 6, 2023
* Drop support for PHP 7.4, require PHP 8.0

* Enforce PHP 8 syntax in phpcs

* Fix static analysis errors

* Move psalm configuration to .dist file

* Set psalm phpVersion through config file

* Run PHPStan on PHP 8.2

* Remove superfluous assertion
alcaeus added a commit that referenced this pull request Apr 11, 2023
* 2.6.x:
  Add $search stage to aggregation pipeline builder (#2516)
  Support new aggregation operators in builder (#2514)
  Drop support for PHP 7.4 (#2515)
  Support new aggregation pipeline stages in builder (#2513)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants