Skip to content

Replace Psalm with PHPStan + Minor fixes - #412

Merged
samdark merged 7 commits into
masterfrom
phpstan
Nov 22, 2026
Merged

samdark merged 7 commits into
masterfrom
phpstan

Conversation

@vjik

@vjik vjik commented Nov 16, 2026 •

Copy link
Copy Markdown
Member
Q A
Is bugfix? ❌
New feature? ❌
Breaks BC? ❌

Summary by Sourcery

Replace Psalm with PHPStan while tightening type declarations and validating container dependency definitions.

Bug Fixes:

  • Validate that a redefined ContainerInterface service resolves to a container instance and report an invalid configuration otherwise.

Enhancements:

  • Replace Psalm with PHPStan for static analysis and update project annotations and configuration accordingly.
  • Tighten exception result types and improve type declarations throughout container configuration and service APIs.
  • Support string keys in tagged service definitions.

Build:

  • Add PHPStan as a development dependency and expose it through the Composer scripts.

CI:

  • Switch the static analysis workflow from Psalm to PHPStan.

Documentation:

  • Update static analysis documentation and remove the obsolete Psalm and type-coverage references.

Tests:

  • Add coverage for string-keyed tags and invalid ContainerInterface redefinitions.

Chores:

  • Remove the project-specific Psalm tooling configuration.

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Remove the class-string return-type promise from container lookups and require the configured ContainerInterface definition to resolve to a container before using it for dependency resolution.

  • src/CompositeContainer.php L31-33, L37 (removed lines), L86 (removed lines)
  • src/Container.php L266-271, L555-576 (+2 small edits)

Narrow the public exception solution methods to always return a string, matching their actual behavior.

  • src/BuildingException.php L44
  • src/NotFoundException.php L61

Specify the public shapes of container configuration and service-provider results so callers can rely on their documented types.

  • src/ContainerConfigInterface.php L7-35 (5 small edits)
  • src/ServiceProviderInterface.php L42, L58

Implementation

Adapt container internals to the revised types, validate dependency-container resolution, and make tagged-service and resetter handling explicit for PHPStan.

  • src/CompositeContainer.php L71-77 (+3 small edits)
  • src/CompositeNotFoundException.php L10, L21-22
  • src/Container.php L48-717 (18 small edits)
  • src/Helpers/DefinitionNormalizer.php L29-37
  • src/Helpers/DefinitionParser.php L55
  • src/StateResetter.php L113-117 (+6 small edits)

Add precise property and accessor documentation types to the immutable container configuration implementation.

  • src/ContainerConfig.php L14-33, L125-129 (+8 small edits)

Configuration

Replace Psalm with PHPStan in the static-analysis workflow, Composer tooling, and analysis configuration while removing the obsolete Psalm setup.

  • .github/workflows/static.yml L7, L22-23
  • composer.json L45, L72
  • phpstan.neon L1-5
  • psalm.xml (deleted)
  • tools/psalm/composer.json (deleted)

Documentation

Update the static-analysis instructions and changelog to describe the PHPStan migration and accompanying behavior and type improvements.

  • CHANGELOG.md L5-6, L15-16
  • docs/internals.md L169-172

Remove the obsolete Psalm type-coverage badge from the project README.

  • README.md L15 (removed lines)

Tests

Cover associative tag keys and verify that a non-container ContainerInterface definition fails clearly during dependency resolution.

  • tests/Unit/ContainerTest.php L1168-1183, L2004-2020

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Nov 16, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/Container.php" line_range="315" />
<code_context>
      * Sets multiple definitions at once.
      *
-     * @param array $config Definitions indexed by their IDs.
+     * @param array<int|string, mixed> $config Definitions indexed by their IDs.
      *
      * @throws InvalidConfigException
</code_context>
<issue_to_address>
**Integer service IDs fail in permissive mode**

When a caller supplies an integer-keyed definition with validation disabled, `addDefinitions()` skips its string-key check when validation is disabled, then passes the integer key to `addDefinition(string $id, ...)`, which raises a `TypeError` instead of accepting the documented input.

Require string definition IDs regardless of validation mode, or change the documented definition types and API behavior so integer keys are not advertised as supported.

Also at `src/ContainerConfig.php:46`, `src/ContainerConfigInterface.php:15`, `src/ServiceProviderInterface.php:42`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/Container.php:315


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/Container.php Resolved
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (05543f3) to head (ed3c41d).

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #412   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       190       192    +2     
===========================================
  Files             11        11           
  Lines            523       535   +12     
===========================================
+ Hits             523       535   +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sourcery-ai
sourcery-ai Bot dismissed their stale review November 16, 2026 08:10

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@vjik
vjik requested a balanced review from Copilot November 16, 2026 08:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@vjik
vjik requested a review from a team November 16, 2026 08:13
@vjik vjik added the status:code review The pull request needs review. label Nov 16, 2026

@samdark samdark left a comment

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 allow keyed service ID arrays in the tag configuration PHPDoc and retain list types for resolved services. Please also avoid promising a class-matching return from get() when configured services or delegated PSR-11 containers can return a different value.

Comment thread src/BuildingException.php Resolved
Comment thread src/NotFoundException.php
}

public function getSolution(): ?string
public function getSolution(): string

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Narrowing the type in the implementation is OK.

Comment thread CHANGELOG.md Resolved
Comment thread src/ContainerConfig.php Resolved
Comment thread src/CompositeContainer.php Resolved
vjik added 3 commits November 21, 2026 15:27
# Conflicts:
#	src/CompositeContainer.php
#	tools/psalm/composer.json
…terface definition check

As suggested in #412 review: there is no guarantee that a configured service
or a delegated PSR-11 container returns an instance of the class given as ID,
so "get()" no longer promises a class-matching return type.

Internal call sites that relied on the inference were adjusted:
- CompositeContainer always returns a StateResetter for StateResetter::class,
  so the delegates reset call is annotated with a phpstan-ignore.
- New private getDependencyContainer() validates that the
  ContainerInterface::class definition is actually a container and throws
  InvalidConfigException with a clear message otherwise.
@vjik
vjik requested a review from samdark November 21, 2026 13:11
@samdark
samdark merged commit 7287ca4 into master Nov 22, 2026
37 checks passed
@samdark
samdark deleted the phpstan branch November 22, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants