soyhuce / phpstan-extension
Extra rules for phpstan analysis
Fund package maintenance!
soyhuce
Installs: 11 994
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- illuminate/support: ^10.0 || ^11.0
- nesbot/carbon: ^2.0 || ^3.0
- phpstan/phpstan: ^1.10.57
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.7
- larastan/larastan: ^2.0.1
- nunomaduro/collision: ^7.10 || ^8.0
- orchestra/testbench: ^8.0 || ^9.0
- pestphp/pest: ^2.24
- pestphp/pest-plugin-laravel: ^2.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2024-11-08 07:49:42 UTC
README
Strict rules for PHPStan and helpers for Laravel
Installation
You can install the package via composer:
composer require --dev soyhuce/phpstan-extension
If you use phpstan/extension-installer
, the extension is automatically installed and you're all set.
Otherwise, you need to add the extension in your phpstan.neon
file:
includes: - ./vendor/soyhuce/phpstan-extension/extension.neon
If you want only a subset of the rules, check the /vendor/soyhuce/phpstan-extension/extension.neon
file and copy the
rules you want to use.
Rules
CarbonCopyRule
Forbids usage of \Carbon\CarbonInterface::copy()
because it is probably linked to usage of a mutable DateTime.
<?php $datetime->copy()->addDay(); // ko $datetime->addDay(); // ok
NoAliasUseRule
Forbids usage of Laravel aliases and suggests to use the real class name instead.
<?php use Auth; // ko use Illuminate\Support\Facades\Auth; // ok
NoMutableDateTimeStaticCallRule
Forbids usage of static methods on \DateTime
and its child classes.
<?php \Illuminate\Support\Carbon::create($year, $month, $day); // ko \Illuminate\Support\Facade\Date::create($year, $month, $day); // ok \Carbon\CarbonImmutable::create($year, $month, $day); // ok
NoMutableDateTimeUseRule
Forbids import of \DateTime
and its child classes.
<?php use Illuminate\Support\Carbon; // ko use Carbon\Carbon; // ko use Carbon\CarbonInterface; // ok use Carbon\ImmutableCarbon; // ok
NoNewMutableDateTimeRule
Forbids usage of new \DateTime()
and its child classes.
<?php $dateTime = new Illuminate\Support\Carbon($date); // ko $dateTime = new Carbon\Carbon($date); // ko $dateTime = new Carbon\ImmutableCarbon($date); // ok
Extensions
RequestDateExtension
Provides return type for \Illuminate\Support\Request::date()
method.
use Carbon\FactoryImmutable; use Illuminate\Support\Facades\Date; Date::use(FactoryImmutable::class); $request->date('published_at'); // CarbonImmutable|null
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.