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

Phpstorm Attributes Laravel Package

jetbrains/phpstorm-attributes

JetBrains PhpStorm Attributes for PHP 8+: add IDE-only attributes like Deprecated, ArrayShape, ObjectShape, and Immutable to improve code completion and static analysis. Bundled with PhpStorm 2020.3+, optional composer dev dependency to avoid “Class not found” in other tools.

View on GitHub
Deep Wiki
Context7

Getting Started

Install as a dev dependency with composer require --dev jetbrains/phpstorm-attributes. No bootstrapping or config changes are needed — PhpStorm 2020.3+ recognizes these attributes out of the box. Start by applying #[Deprecated] to methods scheduled for removal (e.g., deprecated APIs in Laravel service providers), and use #[ArrayShape] on functions returning structured arrays like config() results or API response payloads. These two yield the biggest immediate IDE improvement with minimal effort.

Implementation Patterns

  • Refactoring Safeguards: Tag deprecated methods/properties with #[Deprecated(reason: '…', replacement: '…')] in Laravel packages to provide inline warnings and automated find/replace hints in PhpStorm — invaluable during upgrades (e.g., Laravel 10 → 11 migrations).
  • Type-Safe Configuration & DTOs: Use #[ArrayShape([...])] on methods returning config structures (e.g., custom service provider configs) or #[ObjectShape([...])] for dynamic object hydrations from Eloquent or external APIs — enables autocomplete for keys like 'timeout' => 'int'.
  • Performance & Safety Tuning: Annotate pure helper functions (#[Pure]) in utility classes to let PhpStorm flag unused calls and improve type inference. Mark #[NoReturn] methods like abort(403) wrappers or terminal CLI commands to improve dead-code detection.
  • Input Validation Clarity: Apply #[ExpectedValues(valuesFromClass: Status::class)] on controller/route parameters (Status::class being an enum) to restrict autocomplete and surface invalid value warnings at edit time.
  • DTO Immutability Contracts: Apply #[Immutable] to value objects (e.g., Money, EmailAddress) to signal immutability expectations — PhpStorm will warn about direct writes and integrate with static analysis tools for verification.

Gotchas and Tips

  • IDE-Only Runtime: These attributes have zero runtime impact — PHP ignores them unless a tool like Psalm/PHPStan with a dedicated plugin (e.g., phpstan-phpstorm) interprets them. Safe to commit without conditional checks.
  • PHP Version Gotchas: For PHP ≤7.4, attributes like #[ArrayShape([...])] must be written on a single line (no newlines in the attribute). Prefer multiline formatting only when targeting PHP ≥8.0.
  • Null Handling: In ArrayShape, optional keys require explicit nullable types: 'user' => '?App\Models\User' or 'count' => '?int'. PhpStorm uses this for null-safety diagnostics.
  • Name Resolution: When referencing classes in valuesFromClass, ObjectShape, or ArrayShape, always use fully qualified names or use statements — PhpStorm resolves attributes statically and may misinfer unqualified names.
  • Tooling Integration: Enable the phpstan-phpstorm extension in PHPStan to surface these attributes in CI/CD pipelines — ensures #[Immutable] and #[Pure] contracts are enforced beyond the IDE.
  • Avoid Over-Annotation: Only annotate public-facing APIs, critical data flows, and shared DTOs. Bombarding internal methods with attributes harms readability and offers diminishing returns. Focus on areas where IDE hints reduce bugs (e.g., complex array transformations or legacy code interactions).
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