Skip to content

Adopt larastan and resolve PHPStan level 2 errors#616

Draft
pushpak1300 wants to merge 2 commits into
0.xfrom
phpstan-larastan-level-2
Draft

Adopt larastan and resolve PHPStan level 2 errors#616
pushpak1300 wants to merge 2 commits into
0.xfrom
phpstan-larastan-level-2

Conversation

@pushpak1300
Copy link
Copy Markdown
Member

Bumping phpstan to level 2 surfaced 180 errors, most of them Laravel-shaped: Storage::disk()->mimeType() on the Filesystem contract, higher-order collection proxies (->map->delta->join('')), facade returns, etc. Fixing those with vanilla phpstan means writing workarounds that obscure intent.

Switching to larastan resolves the Laravel-specific noise outright and surfaces only the real structural gaps in the codebase, which this PR addresses.

Real fixes (not larastan stubs)

A new base contract makes the four methods every provider exposes part of the type system instead of being only on the abstract Providers\Provider class:

// before: gateways accept FileProvider but call methods on the abstract class
$provider->name(); // PHPStan: method not found on FileProvider

// after: Contracts\Providers\Provider declares name(), driver(),
// providerCredentials(), additionalConfiguration(). Every capability
// contract extends it.

A new Contracts\RemembersConversation interface replaces class_uses_recursive sniffing for conversation-aware agents:

// before
if (in_array(RemembersConversations::class, class_uses_recursive($agent))
    && $agent->hasConversationParticipant()) { ... }

// after
if ($agent instanceof RemembersConversation
    && $agent->hasConversationParticipant()) { ... }

BC note: StoreProvider::addFileToStore gains an optional array $metadata = [] parameter to match the ManagesStores trait implementation. Third-party implementers will need to add it.

Switches the static analyzer from vanilla phpstan/phpstan to
larastan/larastan and fixes the resulting level 2 errors. Adds two new
contracts (Contracts\Providers\Provider, Contracts\RemembersConversation)
so capability providers and conversation-aware agents are discoverable
via interfaces rather than abstract-class identity or
class_uses_recursive checks.
@pushpak1300 pushpak1300 force-pushed the phpstan-larastan-level-2 branch from 4174128 to c7d1825 Compare May 17, 2026 19:10
@danielhe4rt
Copy link
Copy Markdown

Thought all laravel packages we're enforced on phpstan lvl.5 minimum by default

this will break any contract?

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