Skip to content

Conversation

@sasezaki
Copy link
Contributor

Description

Updated PHPDoc return type annotations from ApiProblem to $this for fluent interface methods.

The change affects five setter methods:

  • setTitle()
  • setType()
  • setDetail()
  • setInstance()
  • setStatus()

Motivation and context

This change improves type inference accuracy in IDEs and static analysis tools for subclass ApiProblem.

class MySubApiProblem extends ApiProblem
{
     /** @return $this */
    public function some()
    {
        // do something
        return $this;
    }
}

(new MySubApiProblem)
 ->setTitle($title)
 ->some()  // static analysis would report error
 ->setStatus();

How has this been tested?

  • This is a documentation-only change that does not affect runtime behavior:

  • I confirmed that the number of errors did not increase when running PHPStan.

./vendor/bin/phpstan analyse
./vendor/bin/phpstan analyse --level=8 // 20 errors
./vendor/bin/phpstan analyse --level=10 // 61 errors

Screenshots (if appropriate)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have read the CONTRIBUTING document.
  • My pull request addresses exactly one patch/feature.
  • I have created a branch for this patch/feature.
  • Each individual commit in the pull request is meaningful.
  • I have added tests to cover my changes.
    • If it is needed to add new type test (eg. PHPStan's assertType) , I would add.
  • If my change requires a change to the documentation, I have updated it accordingly.

@Crell Crell merged commit 4e93e38 into Crell:master Dec 15, 2025
14 checks passed
@Crell
Copy link
Owner

Crell commented Dec 15, 2025

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