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

Type Perfect Laravel Package

rector/type-perfect

Type Perfect adds 10 PHPStan rules to tighten type declarations: replace empty/isset checks with instanceof for precise narrowing, prefer explicit getters over magic array access, and enforce interface signatures. Easy to enable even on legacy code; improves reliability fast.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: Perfect alignment with Laravel's PHPStan-based static analysis ecosystem. The package extends PHPStan rules without modifying core framework behavior, making it ideal for Laravel's common legacy codebases where strict typing is desired but not fully implemented. It complements Laravel's existing tooling (e.g., Eloquent, Pest) by targeting type safety gaps that Laravel's default configuration misses.

Integration feasibility: High. Requires only composer require and minimal PHPStan config adjustments (via extension-installer or manual neon inclusion). Existing Laravel projects with PHPStan already configured can integrate in <15 minutes with zero code changes. Compatibility with Laravel 8+ (PHP 7.4+) and PHPStan 1.0+ is proven.

Technical risk: Moderate. Initial rule activation may surface hundreds of violations in legacy code, potentially breaking CI pipelines. Third-party dependencies (e.g., Laravel core, vendor packages) may trigger false positives due to dynamic patterns like magic methods or union returns. Requires careful exclusion configuration to avoid noise from external code.

Key questions:

  • What percentage of current properties/methods use mixed, null/false ambiguity, or untyped signatures?
  • How will we handle violations in third-party code (e.g., vendor exclusions in phpstan.neon)?
  • Does the team have PHPStan expertise to interpret violations (e.g., distinguishing true type errors from false positives in Eloquent relationships)?
  • Are there Laravel-specific edge cases (e.g., dynamic model attributes, polymorphic relationships) that may conflict with strict typing rules?

Integration Approach

Stack fit: Ideal for Laravel 8+ (PHP 7.4+) and Laravel 9+ (PHP 8.0+). Fully compatible with PHPStan 1.0+, Pest, PHPUnit, and existing phpstan.neon configurations. Works seamlessly with Laravel's service container and Eloquent models when configured to exclude magic property/method usage in specific contexts.

Migration path:

  1. Phase 1 (Low risk): Enable null_over_false and no_mixed_property rules. Fixes common false/null confusion and eliminates PHPStan blind spots for properties.
  2. Phase 2 (Medium risk): Add no_mixed_caller to catch method typos and signature mismatches. Requires validation of dynamic method calls (e.g., Eloquent __call usage).
  3. Phase 3 (High impact): Enable narrow_param and narrow_return after validating concrete type usage in codebase. Start with private methods before public APIs.

Compatibility: Works with existing PHPStan rule sets (e.g., larastan, symfony rules) without conflicts. Requires phpstan/extension-installer for automatic config loading or manual inclusion of vendor/rector/type-perfect/config/extension.neon in phpstan.neon.

Sequencing: Prioritize rules by business impact: null_over_false (prevents runtime errors from type confusion) → no_mixed_property (fixes PHPStan blind spots) → narrow_param (reduces parameter-related bugs) → narrow_return (improves API contract clarity). Test each phase in staging before CI enforcement.

Operational Impact

Maintenance: Low ongoing effort after initial setup. Rules run automatically in CI pipelines with minimal configuration. Requires periodic review of exclusion lists for third-party code and validation of new rule violations. Updates to the package are infrequent and backward-compatible.

Support: Requires basic PHPStan knowledge to interpret violation reports (e.g., distinguishing false positives in magic methods). Documentation is clear but lacks Laravel-specific examples—team may need to create internal guides for common Laravel patterns (e.g., Eloquent model property typing). Community support via GitHub issues is responsive but limited due to small user base (101 stars).

Scaling: Rules scale linearly with codebase size. For large monorepos, use PHPStan's ignoreErrors to exclude vendor directories and legacy modules. Performance impact is negligible (PHPStan runs in milliseconds per file). Avoid enabling all rules simultaneously in codebases >50k LOC to prevent CI timeouts during initial runs.

Failure modes:

  • CI failures due to unaddressed violations (mitigated by gradual rule activation)
  • False positives in dynamic Laravel patterns (e.g., __call for Eloquent relationships) requiring exclusions
  • Misconfigured phpstan.neon leading to rule conflicts (e.g., duplicate parameters.type_perfect declarations)

Ramp-up: Developers with PHPStan experience can onboard in <1 hour. New developers may need 2–4 hours to understand violation reports and fix strategies (e.g., converting false returns to null). Provide quick-reference guides for common fixes (e.g., "How to handle mixed property in a Model class"). Team training should focus on interpreting no_mixed_caller errors for method typos and narrow_return for factory methods.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport