Skip to content

PHPDoc: use @return $this for fluent methods#1362

Merged
PowerKiKi merged 1 commit intoPHPOffice:masterfrom
caugner:return-this
Mar 2, 2020
Merged

PHPDoc: use @return $this for fluent methods#1362
PowerKiKi merged 1 commit intoPHPOffice:masterfrom
caugner:return-this

Conversation

@caugner
Copy link
Contributor

@caugner caugner commented Feb 16, 2020

This is:

- [x] a bugfix
- [ ] a new feature

Checklist:

Why this change is needed?

  • Some @return annotations used wrong casing (e.g. @return CSV instead of @return Csv)
  • Most classes can be extended and therefore the annotation @return static would be more appropriate to avoid inadvertent type narrowing.
  • The @return $this annotation is more explicit than @return static.

@caugner caugner requested a review from PowerKiKi February 17, 2020 21:06
@caugner
Copy link
Contributor Author

caugner commented Feb 29, 2020

@PowerKiKi Any chance to get this merged? This fixes errors reported by Psalm like this:

ERROR: InvalidClass - src/.../ExcelExport.php:135:17 - Class or interface PhpOffice\PhpSpreadsheet\Writer\CSV has wrong casing
                $writer->setDelimiter(',')

Fluent methods, especially setters, return the object on which are
called. This is documented in PHPDoc using the `$this` keyword, which
is equivalent to `static` with the additional notion of object identity.
This helps IDEs and static analysis tools provide more meaningful output.
@PowerKiKi PowerKiKi merged commit ffb0d21 into PHPOffice:master Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants