Skip to content

DisableConstructorPatch: make optional constructor parameters nullable explicitly#632

Merged
stof merged 1 commit intophpspec:masterfrom
W0rma:php84-explicit-nullable-types
Oct 11, 2024
Merged

DisableConstructorPatch: make optional constructor parameters nullable explicitly#632
stof merged 1 commit intophpspec:masterfrom
W0rma:php84-explicit-nullable-types

Conversation

@W0rma
Copy link
Copy Markdown
Contributor

@W0rma W0rma commented Oct 3, 2024

This PR tries to fix #625 (comment)

\assert($constructor !== null);
foreach ($constructor->getArguments() as $argument) {
$argument->setDefault(null);
if (\PHP_VERSION_ID < 80400) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest doing that for all versions instead, to avoid different behavior between PHP versions (making a type explicitly nullable is supported on PHP 7.1+, which covers more than our target versions)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

$types = $argument->getTypeNode()->getNonNullTypes();
if ([] == $types || ['mixed'] == $types) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please use strict comparisons here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Implicitly nullable types are deprecated in PHP 8.4
@W0rma
Copy link
Copy Markdown
Contributor Author

W0rma commented Oct 4, 2024

#633 should fix the CI (cs fixer + phpstan)

@Jean85
Copy link
Copy Markdown
Contributor

Jean85 commented Oct 11, 2024

This should receive the PHP 8.4 label

@stof stof added the PHP8.4 label Oct 11, 2024
@stof stof merged commit f425512 into phpspec:master Oct 11, 2024
@W0rma W0rma deleted the php84-explicit-nullable-types branch October 12, 2024 08:52
Jean85 added a commit to facile-it/paraunit that referenced this pull request Oct 30, 2024
Jean85 added a commit to facile-it/paraunit that referenced this pull request Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants