generated from Soyhuce/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
506cb23
commit 37ecdad
Showing
42 changed files
with
866 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
database/migrations/create_phpstan_extension_table.php.stub
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
- class: Soyhuce\PhpstanExtension\ReturnTypes\DateExtension | ||
tags: | ||
- phpstan.broker.dynamicStaticMethodReturnTypeExtension | ||
|
||
- class: Soyhuce\PhpstanExtension\ReturnTypes\NowAndTodayExtension | ||
tags: | ||
- phpstan.broker.dynamicFunctionReturnTypeExtension | ||
|
||
rules: | ||
- Soyhuce\PhpstanExtension\Rules\CarbonCopyRule | ||
- Soyhuce\PhpstanExtension\Rules\NoAliasUseRule | ||
- Soyhuce\PhpstanExtension\Rules\NoMutableDateTimeStaticCallRule | ||
- Soyhuce\PhpstanExtension\Rules\NoMutableDateTimeUseRule | ||
- Soyhuce\PhpstanExtension\Rules\NoNewMutableDateTimeRule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soyhuce\PhpstanExtension\ReturnTypes; | ||
|
||
use Illuminate\Support\Facades\Date; | ||
use PhpParser\Node\Expr\StaticCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\Constant\ConstantBooleanType; | ||
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\Type; | ||
use PHPStan\Type\TypeCombinator; | ||
use function get_class; | ||
use function in_array; | ||
|
||
class DateExtension implements DynamicStaticMethodReturnTypeExtension | ||
{ | ||
public function getClass(): string | ||
{ | ||
return Date::class; | ||
} | ||
|
||
public function isStaticMethodSupported(MethodReflection $methodReflection): bool | ||
{ | ||
return in_array( | ||
$methodReflection->getName(), | ||
[ | ||
'create', | ||
'createFromDate', | ||
'createFromTime', | ||
'createFromTimeString', | ||
'createFromTimestamp', | ||
'createFromTimestampMs', | ||
'createFromTimestampUTC', | ||
'createMidnightDate', | ||
'fromSerialized', | ||
'getTestNow', | ||
'instance', | ||
'isMutable', | ||
'maxValue', | ||
'minValue', | ||
'now', | ||
'parse', | ||
'today', | ||
'tomorrow', | ||
'yesterday', | ||
'createFromFormat', | ||
'createSafe', | ||
'make', | ||
] | ||
); | ||
} | ||
|
||
public function getTypeFromStaticMethodCall( | ||
MethodReflection $methodReflection, | ||
StaticCall $methodCall, | ||
Scope $scope, | ||
): Type { | ||
$dateType = new ObjectType(get_class(now())); | ||
|
||
if (in_array($methodReflection->getName(), ['createFromFormat', 'createSafe'])) { | ||
return TypeCombinator::union($dateType, new ConstantBooleanType(false)); | ||
} | ||
|
||
if (in_array($methodReflection->getName(), ['getTestNow', 'make'])) { | ||
return TypeCombinator::addNull($dateType); | ||
} | ||
|
||
return $dateType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Soyhuce\PhpstanExtension\ReturnTypes; | ||
|
||
use PhpParser\Node\Expr\FuncCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Reflection\FunctionReflection; | ||
use PHPStan\Type\DynamicFunctionReturnTypeExtension; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\Type; | ||
use function get_class; | ||
|
||
class NowAndTodayExtension implements DynamicFunctionReturnTypeExtension | ||
{ | ||
public function isFunctionSupported(FunctionReflection $functionReflection): bool | ||
{ | ||
return $functionReflection->getName() === 'now' || $functionReflection->getName() === 'today'; | ||
} | ||
|
||
public function getTypeFromFunctionCall( | ||
FunctionReflection $functionReflection, | ||
FuncCall $functionCall, | ||
Scope $scope, | ||
): Type { | ||
return new ObjectType(get_class(now())); | ||
} | ||
} |
Oops, something went wrong.