Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Larastan Laravel Package

nunomaduro/larastan

Larastan is a PHPStan extension for Laravel that adds strong type inference and “code analysis” by booting the app container. It understands Laravel’s magic, finds bugs early, and improves code quality and developer productivity.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Shift from reactive to proactive quality assurance: Integrate static analysis into CI/CD pipelines to catch bugs before they reach testing or production, reducing technical debt and developer frustration.
  • Enforce consistency in Laravel projects: Standardize code quality across teams by leveraging PHPStan’s strict typing while accommodating Laravel’s "magic" (e.g., dynamic method calls, service container).
  • Accelerate onboarding: Reduce ramp-up time for new developers by surfacing type-related errors early, with clear documentation and baseline support for legacy code.
  • Build vs. Buy: Buy (Larastan) to avoid reinventing static analysis for Laravel, while customizing rules via phpstan.neon for project-specific needs.
  • Use cases:
    • New projects: Enforce high-quality code from day one (Level 5+).
    • Legacy refactoring: Use baseline files to incrementally improve code quality without breaking existing functionality.
    • Team alignment: Standardize PHPDoc conventions and Laravel-specific types (e.g., Collection, Model casts).
    • Performance: Identify type-related bottlenecks (e.g., mixed return types) before they impact runtime.

When to Consider This Package

Adopt Larastan if:

  • Your team uses Laravel 11.15+ and PHP 8.2+ (or Laravel 9+ with v1.x).
  • You prioritize developer productivity over pure runtime performance (static analysis adds ~5–10s to builds).
  • Your codebase relies heavily on Laravel’s magic (e.g., dynamic facades, service container) but needs stricter typing.
  • You’re willing to invest in PHPDoc maintenance (e.g., @return, @var) for better type inference.
  • You want actionable feedback without writing tests (e.g., "This method returns null but is documented as @return int").

Look elsewhere if:

  • Your project is small or experimental (overhead may not justify benefits).
  • You can’t tolerate false positives (Larastan’s Laravel-specific rules may need tuning).
  • Your team lacks buy-in for static analysis (requires cultural shift toward proactive quality).
  • You use heavily dynamic code (e.g., eval, call_user_func) that static analysis struggles with.
  • You’re on Laravel <9 or PHP <8.2 (use v1.x, but expect limited features).

How to Pitch It (Stakeholders)

For Executives: *"Larastan turns Laravel’s ‘magic’ into a competitive advantage. By integrating static analysis into our workflow, we’ll:

  • Reduce bugs in production by catching type errors early (e.g., null returns, undefined methods).
  • Lower onboarding time by surfacing clear, actionable feedback for new hires.
  • Future-proof our codebase with stricter typing, making it easier to refactor and scale. Think of it as ‘GitHub Copilot for code quality’—but for Laravel. The upfront cost (a few CI minutes) pays off in fewer fire drills and happier developers."

For Engineering Teams: *"Larastan is like PHPStan on steroids for Laravel. It:

  • Understands Laravel’s quirks (e.g., service container, dynamic facades) that break generic static analyzers.
  • Works alongside your existing tests—no need to rewrite code, just fix errors as you go (use baselines for legacy code).
  • Integrates seamlessly with your workflow: Add it to composer.json, configure phpstan.neon, and run ./vendor/bin/phpstan analyse in CI. Start with Level 3 (moderate) to avoid burnout, then ramp up. Ignore known false positives (see errors-to-ignore.md) and focus on high-impact fixes first."

For Developers: *"This is your new best friend for:

  • ‘Why is this method returning null?’ → Larastan tells you before you debug.
  • ‘How do I type this Eloquent relationship?’ → Custom PHPDoc types for Model, Collection, etc.
  • ‘My CI is slow’ → Run it locally first (./vendor/bin/phpstan analyse --memory-limit=2G). Pro tip: Use @phpstan-ignore-line sparingly—aim to fix the root cause. And if you’re stuck, check the rules docs for Laravel-specific fixes."
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony