Strict rules for PHPStan and helpers for Laravel
You can install the package via composer:
composer require --dev soyhuce/phpstan-extensionIf 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.neonIf 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.
Forbids usage of \Carbon\CarbonInterface::copy() because it is probably linked to usage of a mutable DateTime.
<?php
$datetime->copy()->addDay(); // ko
$datetime->addDay(); // okForbids usage of Laravel aliases and suggests to use the real class name instead.
<?php
use Auth; // ko
use Illuminate\Support\Facades\Auth; // okForbids 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); // okForbids import of \DateTime and its child classes.
<?php
use Illuminate\Support\Carbon; // ko
use Carbon\Carbon; // ko
use Carbon\CarbonInterface; // ok
use Carbon\ImmutableCarbon; // okForbids 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); // okProvides 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|nullcomposer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.