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

Add @return $this annotation to methods #3780

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

lorenzolosa
Copy link
Contributor

#3777 and #3779 added generics to InteractsWithMedia and FileAdder, which improves PHPStan recognition of return types. However, PHPStan is still unable to follow through chaining; for instance, it will interpret the return value of:

$this->addMedia($file)
    ->usingFileName($filename)
    ->toMediaCollection('collection');

as the base Media class, even if an extended class has been specified.

This PR fixes that by listing the return type of a bunch of methods as $this. These include methods in the FileAdder class, needed for the example above; but I have also included several others (mostly with generics, where I believe it's most useful, but not only).

@freekmurze freekmurze merged commit b808162 into spatie:main Feb 10, 2025
2 checks passed
@freekmurze
Copy link
Member

Thanks!

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.

2 participants