soyhuce / phpstan-extension
PHPStan 分析的额外规则
1.1.0
2024-04-19 06:58 UTC
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-09-08 07:28:14 UTC
README
PHPStan 的严格规则和 Laravel 辅助工具
安装
您可以通过 composer 安装此包
composer require --dev soyhuce/phpstan-extension
如果您使用 phpstan/extension-installer
,则扩展将自动安装,您就绪了。
否则,您需要在您的 phpstan.neon
文件中添加扩展
includes: - ./vendor/soyhuce/phpstan-extension/extension.neon
如果您只想使用规则的一部分,请查看 /vendor/soyhuce/phpstan-extension/extension.neon
文件,并复制您想使用的规则。
规则
CarbonCopyRule
禁止使用 \Carbon\CarbonInterface::copy()
,因为它可能涉及到可变 DateTime 的使用。
<?php $datetime->copy()->addDay(); // ko $datetime->addDay(); // ok
NoAliasUseRule
禁止使用 Laravel 别名,并建议使用真实类名。
<?php use Auth; // ko use Illuminate\Support\Facades\Auth; // ok
NoMutableDateTimeStaticCallRule
禁止在 \DateTime
和其子类上使用静态方法。
<?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
禁止导入 \DateTime
和其子类。
<?php use Illuminate\Support\Carbon; // ko use Carbon\Carbon; // ko use Carbon\CarbonInterface; // ok use Carbon\ImmutableCarbon; // ok
NoNewMutableDateTimeRule
禁止使用 new \DateTime()
和其子类。
<?php $dateTime = new Illuminate\Support\Carbon($date); // ko $dateTime = new Carbon\Carbon($date); // ko $dateTime = new Carbon\ImmutableCarbon($date); // ok
扩展
RequestDateExtension
为 \Illuminate\Support\Request::date()
方法提供返回类型。
use Carbon\FactoryImmutable; use Illuminate\Support\Facades\Date; Date::use(FactoryImmutable::class); $request->date('published_at'); // CarbonImmutable|null
测试
composer test
变更日志
请参阅 变更日志 了解最近的变化。
贡献
请参阅 贡献指南 获取详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。