From 5f1a59f7b3a7dff382a8c811a2d3fdf3a4247b74 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Sat, 23 Sep 2023 22:18:14 -0700 Subject: [PATCH] Update phpcs and phpstan --- .github/workflows/lint-php.yml | 4 + larastan-extension.neon | 550 +++++++++++++++++++++++++++++++++ phpcs.xml | 154 ++++++++- phpstan.neon | 4 + 4 files changed, 697 insertions(+), 15 deletions(-) create mode 100644 larastan-extension.neon diff --git a/.github/workflows/lint-php.yml b/.github/workflows/lint-php.yml index 63167f42c..2a874a6a3 100644 --- a/.github/workflows/lint-php.yml +++ b/.github/workflows/lint-php.yml @@ -1,6 +1,10 @@ name: Lint PHP on: + push: + branches: + - master + - dist workflow_dispatch: jobs: diff --git a/larastan-extension.neon b/larastan-extension.neon new file mode 100644 index 000000000..715d60244 --- /dev/null +++ b/larastan-extension.neon @@ -0,0 +1,550 @@ +parameters: + universalObjectCratesClasses: + - Illuminate\Http\Request + - Illuminate\Support\Optional + earlyTerminatingFunctionCalls: + - abort + - dd + excludePaths: + - *.blade.php + mixinExcludeClasses: + - Eloquent + bootstrapFiles: + - bootstrap.php + checkOctaneCompatibility: false + noModelMake: true + noUnnecessaryCollectionCall: true + noUnnecessaryCollectionCallOnly: [] + noUnnecessaryCollectionCallExcept: [] + squashedMigrationsPath: [] + databaseMigrationsPath: [] + disableMigrationScan: false + disableSchemaScan: false + viewDirectories: [] + checkModelProperties: false + checkPhpDocMissingReturn: false + checkUnusedViews: false + +parametersSchema: + checkOctaneCompatibility: bool() + noModelMake: bool() + noUnnecessaryCollectionCall: bool() + noUnnecessaryCollectionCallOnly: listOf(string()) + noUnnecessaryCollectionCallExcept: listOf(string()) + databaseMigrationsPath: listOf(string()) + disableMigrationScan: bool() + viewDirectories: listOf(string()) + squashedMigrationsPath: listOf(string()) + disableSchemaScan: bool() + checkModelProperties: bool() + checkUnusedViews: bool() + +conditionalTags: + NunoMaduro\Larastan\Rules\NoModelMakeRule: + phpstan.rules.rule: %noModelMake% + NunoMaduro\Larastan\Rules\NoUnnecessaryCollectionCallRule: + phpstan.rules.rule: %noUnnecessaryCollectionCall% + NunoMaduro\Larastan\Rules\OctaneCompatibilityRule: + phpstan.rules.rule: %checkOctaneCompatibility% + NunoMaduro\Larastan\Rules\ModelProperties\ModelPropertyRule: + phpstan.rules.rule: %checkModelProperties% + NunoMaduro\Larastan\Rules\ModelProperties\ModelPropertyStaticCallRule: + phpstan.rules.rule: %checkModelProperties% + NunoMaduro\Larastan\Rules\UnusedViewsRule: + phpstan.rules.rule: %checkUnusedViews% + +services: + - + class: NunoMaduro\Larastan\Methods\RelationForwardsCallsExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Methods\ModelForwardsCallsExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Methods\EloquentBuilderForwardsCallsExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Methods\HigherOrderTapProxyExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Methods\HigherOrderCollectionProxyExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Methods\StorageMethodsClassReflectionExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Methods\Extension + tags: + - phpstan.broker.methodsClassReflectionExtension + - + class: NunoMaduro\Larastan\Methods\ModelFactoryMethodsClassReflectionExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + - + class: NunoMaduro\Larastan\Methods\RedirectResponseMethodsClassReflectionExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + - + class: NunoMaduro\Larastan\Methods\MacroMethodsClassReflectionExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + - + class: NunoMaduro\Larastan\Methods\ViewWithMethodsClassReflectionExtension + tags: + - phpstan.broker.methodsClassReflectionExtension + + - + class: NunoMaduro\Larastan\Properties\ModelAccessorExtension + tags: + - phpstan.broker.propertiesClassReflectionExtension + + - + class: NunoMaduro\Larastan\Properties\ModelPropertyExtension + tags: + - phpstan.broker.propertiesClassReflectionExtension + + - + class: NunoMaduro\Larastan\Properties\HigherOrderCollectionProxyPropertyExtension + tags: + - phpstan.broker.propertiesClassReflectionExtension + + - + class: NunoMaduro\Larastan\Types\RelationDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\Types\ModelRelationsDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\HigherOrderTapProxyExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\ContainerArrayAccessDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + arguments: + className: Illuminate\Contracts\Container\Container + - + class: NunoMaduro\Larastan\ReturnTypes\ContainerArrayAccessDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + arguments: + className: Illuminate\Container\Container + - + class: NunoMaduro\Larastan\ReturnTypes\ContainerArrayAccessDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + arguments: + className: Illuminate\Foundation\Application + - + class: NunoMaduro\Larastan\ReturnTypes\ContainerArrayAccessDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + arguments: + className: Illuminate\Contracts\Foundation\Application + + - + class: NunoMaduro\Larastan\Properties\ModelRelationsExtension + tags: + - phpstan.broker.propertiesClassReflectionExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\ModelFactoryDynamicStaticMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\ModelDynamicStaticMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\AppMakeDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\AuthExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\GuardDynamicStaticMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\AuthManagerExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\DateExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\GuardExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\RequestFileExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\RequestRouteExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\RequestUserExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\EloquentBuilderExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\RelationFindExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\RelationCollectionExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\ModelFindExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\BuilderModelFindExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\TestCaseExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\Support\CollectionHelper + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\AuthExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\CollectExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\NowAndTodayExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\ResponseExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\ValidatorExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\CollectionFilterDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\CollectionWhereNotNullDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\CollectionGenericStaticMethodDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\NewModelQueryDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\FactoryDynamicMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\CollectionGenericStaticMethodDynamicStaticMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\Types\AbortIfFunctionTypeSpecifyingExtension + tags: + - phpstan.typeSpecifier.functionTypeSpecifyingExtension + arguments: + methodName: 'abort' + negate: false + + - + class: NunoMaduro\Larastan\Types\AbortIfFunctionTypeSpecifyingExtension + tags: + - phpstan.typeSpecifier.functionTypeSpecifyingExtension + arguments: + methodName: 'abort' + negate: true + + - + class: NunoMaduro\Larastan\Types\AbortIfFunctionTypeSpecifyingExtension + tags: + - phpstan.typeSpecifier.functionTypeSpecifyingExtension + arguments: + methodName: throw + negate: false + + - + class: NunoMaduro\Larastan\Types\AbortIfFunctionTypeSpecifyingExtension + tags: + - phpstan.typeSpecifier.functionTypeSpecifyingExtension + arguments: + methodName: throw + negate: true + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\AppExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\ValueExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\StrExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\Helpers\TapExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\StorageDynamicStaticMethodReturnTypeExtension + tags: + - phpstan.broker.dynamicStaticMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\Types\GenericEloquentCollectionTypeNodeResolverExtension + tags: + - phpstan.phpDoc.typeNodeResolverExtension + + - + class: NunoMaduro\Larastan\Types\ViewStringTypeNodeResolverExtension + tags: + - phpstan.phpDoc.typeNodeResolverExtension + + - + class: NunoMaduro\Larastan\Rules\OctaneCompatibilityRule + + - + class: NunoMaduro\Larastan\Rules\NoModelMakeRule + + - + class: NunoMaduro\Larastan\Rules\NoUnnecessaryCollectionCallRule + arguments: + onlyMethods: %noUnnecessaryCollectionCallOnly% + excludeMethods: %noUnnecessaryCollectionCallExcept% + + - + class: NunoMaduro\Larastan\Rules\ModelProperties\ModelPropertyRule + + - + class: NunoMaduro\Larastan\Rules\ModelProperties\ModelPropertyStaticCallRule + + - + class: NunoMaduro\Larastan\Types\GenericEloquentBuilderTypeNodeResolverExtension + tags: + - phpstan.phpDoc.typeNodeResolverExtension + - + class: NunoMaduro\Larastan\ReturnTypes\AppEnvironmentReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\Types\ModelProperty\ModelPropertyTypeNodeResolverExtension + tags: + - phpstan.phpDoc.typeNodeResolverExtension + arguments: + active: %checkModelProperties% + + - + class: NunoMaduro\Larastan\Types\RelationParserHelper + arguments: + parser: @currentPhpVersionSimpleDirectParser + + - + class: NunoMaduro\Larastan\Properties\MigrationHelper + arguments: + databaseMigrationPath: %databaseMigrationsPath% + disableMigrationScan: %disableMigrationScan% + parser: @currentPhpVersionSimpleDirectParser + reflectionProvider: @reflectionProvider + + - + class: NunoMaduro\Larastan\Properties\SquashedMigrationHelper + arguments: + schemaPaths: %squashedMigrationsPath% + disableSchemaScan: %disableSchemaScan% + + - + class: NunoMaduro\Larastan\Properties\ModelCastHelper + + - + class: NunoMaduro\Larastan\Rules\ModelProperties\ModelPropertiesRuleHelper + + - + class: NunoMaduro\Larastan\Rules\ModelRuleHelper + + - + class: NunoMaduro\Larastan\Methods\BuilderHelper + arguments: + checkProperties: %checkModelProperties% + + - + class: NunoMaduro\Larastan\Rules\RelationExistenceRule + tags: + - phpstan.rules.rule + + - + class: NunoMaduro\Larastan\Rules\CheckDispatchArgumentTypesCompatibleWithClassConstructorRule + arguments: + dispatchableClass: Illuminate\Foundation\Bus\Dispatchable + tags: + - phpstan.rules.rule + - + class: NunoMaduro\Larastan\Rules\CheckDispatchArgumentTypesCompatibleWithClassConstructorRule + arguments: + dispatchableClass: Illuminate\Foundation\Events\Dispatchable + tags: + - phpstan.rules.rule + - NunoMaduro\Larastan\Properties\Schema\PhpMyAdminDataTypeToPhpTypeConverter + + - + class: NunoMaduro\Larastan\LarastanStubFilesExtension + tags: [phpstan.stubFilesExtension] + + - + class: NunoMaduro\Larastan\Rules\UnusedViewsRule + + - + class: NunoMaduro\Larastan\Collectors\UsedViewFunctionCollector + tags: + - phpstan.collector + + - + class: NunoMaduro\Larastan\Collectors\UsedEmailViewCollector + tags: + - phpstan.collector + + - + class: NunoMaduro\Larastan\Collectors\UsedViewMakeCollector + tags: + - phpstan.collector + + - + class: NunoMaduro\Larastan\Collectors\UsedViewFacadeMakeCollector + tags: + - phpstan.collector + + - + class: NunoMaduro\Larastan\Collectors\UsedRouteFacadeViewCollector + tags: + - phpstan.collector + - + class: NunoMaduro\Larastan\Collectors\UsedViewInAnotherViewCollector + arguments: + parser: @currentPhpVersionSimpleDirectParser + - + class: NunoMaduro\Larastan\Support\ViewFileHelper + arguments: + viewDirectories: %viewDirectories% + + - + class: NunoMaduro\Larastan\ReturnTypes\ApplicationMakeDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\ContainerMakeDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + + - + class: NunoMaduro\Larastan\ReturnTypes\ConsoleCommand\ArgumentDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\ConsoleCommand\HasArgumentDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\ConsoleCommand\OptionDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\ConsoleCommand\HasOptionDynamicReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\TranslatorGetReturnTypeExtension + tags: + - phpstan.broker.dynamicMethodReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\TransHelperReturnTypeExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + - + class: NunoMaduro\Larastan\ReturnTypes\DoubleUnderscoreHelperReturnTypeExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension + + - NunoMaduro\Larastan\ReturnTypes\AppMakeHelper + - NunoMaduro\Larastan\Internal\ConsoleApplicationResolver + - NunoMaduro\Larastan\Internal\ConsoleApplicationHelper + - NunoMaduro\Larastan\Support\HigherOrderCollectionProxyHelper + +rules: + - NunoMaduro\Larastan\Rules\UselessConstructs\NoUselessWithFunctionCallsRule + - NunoMaduro\Larastan\Rules\UselessConstructs\NoUselessValueFunctionCallsRule + - NunoMaduro\Larastan\Rules\DeferrableServiceProviderMissingProvidesRule + - NunoMaduro\Larastan\Rules\ConsoleCommand\UndefinedArgumentOrOptionRule diff --git a/phpcs.xml b/phpcs.xml index 20d38bb53..6c206156e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -3,31 +3,155 @@ Coding Standard app - bootstrap/app.php - database - public/index.php - public/tools.php - public/install.php + config + public + resources routes tests - overrides + + - - - - ./tests/* + + - - - ./tests/* + + + + + + + + /app/Http/Resources/*\.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + *.php + - - ./database/* + database/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */.phpstorm.meta.php + */_ide_helper.php + */database/* + */cache/* + */*.js + */*.css + */*.xml + */*.blade.php + */autoload.php + */storage/* + */docs/* + */vendor/* + */migrations/* + */config/* + */public/index.php + */*.blade.php + */Console/Kernel.php + */Exceptions/Handler.php + */Http/Kernel.php + */Providers/* + */resources/lang/* diff --git a/phpstan.neon b/phpstan.neon index fab9d62c4..1a25958f1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,8 @@ # https://phpstan.org/config-reference +# https://github.com/nunomaduro/larastan + +includes: + - .larastan-extension.neon parameters: