Skip to content

Add generic to DeepCopy::copy method#205

Merged
mnapoli merged 1 commit intomyclabs:1.xfrom
ruudk:patch-1
Jul 4, 2025
Merged

Add generic to DeepCopy::copy method#205
mnapoli merged 1 commit intomyclabs:1.xfrom
ruudk:patch-1

Conversation

@ruudk
Copy link
Contributor

@ruudk ruudk commented Jul 3, 2025

This makes it possible for PHPStan to understand the return type.

This makes it possible for PHPStan to understand the return type.
@mnapoli
Copy link
Member

mnapoli commented Jul 4, 2025

Thanks!

@mnapoli mnapoli merged commit d25e62e into myclabs:1.x Jul 4, 2025
@sebastianbergmann
Copy link

I think this breaks backward compatibility.

Before this change, the DeepCopy::copy($object) method accepted values of type mixed for $object. After this change, it only accepts objects (according to the new type annotations which are checked by PHPStan, the underlying implementation still handles values of type mixed as it did before).

With this change, I get this when running PHPStan for PHPUnit's code:

 ------ ----------------------------------------------------------------------------------------- 
  Line   Framework/TestCase.php                                                                   
 ------ ----------------------------------------------------------------------------------------- 
  1813   Unable to resolve the template type TObject in call to method DeepCopy\DeepCopy::copy()  
         🪪 argument.templateType                                                                 
         💡 See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type   
 ------ ----------------------------------------------------------------------------------------- 

This is the line of code referenced above: https://github.com/sebastianbergmann/phpunit/blob/5984c2c0052a917262cb8df09c02804eb8e4e5b3/src/Framework/TestCase.php#L1813

@ruudk
Copy link
Contributor Author

ruudk commented Jul 5, 2025

I think we should remove the "of object" on the template. That would make it mixed again.

Would that help? If so, I can make the PR.

ruudk added a commit to ruudk/DeepCopy that referenced this pull request Jul 5, 2025
@ruudk ruudk mentioned this pull request Jul 5, 2025
@ruudk
Copy link
Contributor Author

ruudk commented Jul 5, 2025

@sebastianbergmann created this as a possible solution: #206

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