Skip to content

Commit

Permalink
Improvement (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitloong authored Jun 27, 2024
1 parent 04a8c59 commit b62517f
Show file tree
Hide file tree
Showing 33 changed files with 847 additions and 607 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/phplint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on: [push]

name: "CI PHP"
name: "CI PHP lint"

jobs:
test:
Expand All @@ -24,7 +24,7 @@ jobs:
coverage: pcov
extensions: intl, gd, zip, pdo, sqlite, pdo_sqlite, dom, curl, libxml, mbstring, fileinfo, exif, iconv
ini-values: memory_limit=-1,disable_functions="",pcov.exclude="~(vendor|tests|node_modules)~",pcov.directory="./"
php-version: 8.3
php-version: 7.4
tools: composer:v2

- name: Composer Install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phptest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
- push

name: CI PHP
name: "CI PHP test"

jobs:
test:
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
"barryvdh/laravel-ide-helper": "^2.12|dev-master",
"brianium/paratest": "^6.2|^7.4",
"friendsofphp/php-cs-fixer": "^3.5",
"larastan/larastan": "^1.0|^2.0",
"nunomaduro/collision": "^5.3|^6.0|^8.0",
"nunomaduro/larastan": "^1.0|^2.4",
"orchestra/testbench": "^6.15|^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.3|^10.5",
"slevomat/coding-standard": "^8.15",
"spatie/laravel-ray": "^1.23",
"squizlabs/php_codesniffer": "^3.6",
"vimeo/psalm": "^4.8|^5.6"
Expand All @@ -51,7 +52,10 @@
"test-coverage": "phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"laravel": {
Expand Down
201 changes: 194 additions & 7 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?xml version="1.0"?>
<ruleset name="PSR2">
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="laravel-migrations-generator" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Standard Based on PSR2</description>

<file>src</file>
<file>tests</file>

<rule ref="PSR2"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="210"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
<exclude-pattern>tests/resources/database/migrations/*.php</exclude-pattern>

<rule ref="PSR12">
<exclude name="Generic.Files.LineLength"/>
</rule>

<!-- Align corresponding assignment statement tokens -->
Expand All @@ -18,4 +17,192 @@
<property name="error" value="true"/>
</properties>
</rule>

<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>

<!--<rule ref="SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys"/>-->
<rule ref="SlevomatCodingStandard.Arrays.ArrayAccess"/>
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
<rule ref="SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed"/>
<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement"/>
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing"/>
<rule ref="SlevomatCodingStandard.Attributes.AttributesOrder"/>
<rule ref="SlevomatCodingStandard.Attributes.DisallowAttributesJoining"/>
<rule ref="SlevomatCodingStandard.Attributes.DisallowMultipleAttributesPerLine"/>
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/>
<rule ref="SlevomatCodingStandard.Classes.BackedEnumTypeSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
<!--<rule ref="SlevomatCodingStandard.Classes.ClassLength"/>-->
<rule ref="SlevomatCodingStandard.Classes.ClassMemberSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.ClassStructure"/>
<rule ref="SlevomatCodingStandard.Classes.ConstantSpacing"/>
<!-- <rule ref="SlevomatCodingStandard.Classes.DisallowConstructorPropertyPromotion"/>-->
<!--<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>-->
<!--<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition"/>-->
<!--<rule ref="SlevomatCodingStandard.Classes.DisallowMultiPropertyDefinition"/>-->
<rule ref="SlevomatCodingStandard.Classes.DisallowStringExpressionPropertyFetch"/>
<!--<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces"/>-->
<rule ref="SlevomatCodingStandard.Classes.EnumCaseSpacing"/>
<!--<rule ref="SlevomatCodingStandard.Classes.ForbiddenPublicProperty"/>-->
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing"/>
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration"/>
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing"/>
<!--<rule ref="SlevomatCodingStandard.Classes.RequireAbstractOrFinal"/>-->
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
<!--<rule ref="SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature"/>-->
<rule ref="SlevomatCodingStandard.Classes.RequireSelfReference"/>
<rule ref="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
<!--<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing"/>-->
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/>
<rule ref="SlevomatCodingStandard.Commenting.AnnotationName"/>
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration"/>
<!--<rule ref="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode"/>-->
<rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment"/>
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing"/>
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations"/>
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenComments"/>
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
<!--<rule ref="SlevomatCodingStandard.Commenting.RequireOneLineDocComment"/>-->
<!--<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>-->
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>
<!--<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>-->
<rule ref="SlevomatCodingStandard.Complexity.Cognitive">
<properties>
<property name="warningThreshold" value="15"/>
<property name="errorThreshold" value="15"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
<rule ref="SlevomatCodingStandard.ControlStructures.BlockControlStructureSpacing"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch"/>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEmpty"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.DisallowNullSafeObjectOperator"/>-->
<!--<rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>-->
<!--<rule ref="SlevomatCodingStandard.ControlStructures.DisallowTrailingMultiLineTernaryOperator"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.NewWithoutParentheses"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineCondition"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>
<rule ref="SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.RequireSingleLineCondition"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.RequireTernaryOperator"/>
<!--<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
<!--<rule ref="SlevomatCodingStandard.Exceptions.DisallowNonCapturingCatch"/>-->
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/>
<!--<rule ref="SlevomatCodingStandard.Files.FileLength"/>-->
<!--<rule ref="SlevomatCodingStandard.Files.LineLength"/>-->
<!-- <rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName"/>-->
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>
<!--<rule ref="SlevomatCodingStandard.Functions.DisallowArrowFunction"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.DisallowNamedArguments"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.FunctionLength"/>-->
<rule ref="SlevomatCodingStandard.Functions.NamedArgumentSpacing"/>
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction"/>
<!--<rule ref="SlevomatCodingStandard.Functions.RequireMultiLineCall"/>-->
<!--<rule ref="SlevomatCodingStandard.Functions.RequireSingleLineCall"/>-->
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
<!--<rule ref="SlevomatCodingStandard.Functions.StrictCall"/>-->
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
<!--<rule ref="SlevomatCodingStandard.Functions.UnusedParameter"/>-->
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<!--<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>-->
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation">
<properties>
<property name="ignoredAnnotationNames" type="array">
<element value="@phpstan-type"/>
</property>
</properties>
</rule>
<!--<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>-->
<!--<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants"/>-->
<!--<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions"/>-->
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration"/>
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash"/>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>
<!--<rule ref="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>-->
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/>
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
<!--<rule ref="SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator"/>-->
<!--<rule ref="SlevomatCodingStandard.Numbers.RequireNumericLiteralSeparator"/>-->
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
<!--<rule ref="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators"/>-->
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing"/>
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
<rule ref="SlevomatCodingStandard.Operators.RequireOnlyStandaloneIncrementAndDecrementOperators"/>
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing"/>
<!--<rule ref="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall"/>-->
<!--<rule ref="SlevomatCodingStandard.PHP.DisallowReference"/>-->
<rule ref="SlevomatCodingStandard.PHP.ForbiddenClasses"/>
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
<rule ref="SlevomatCodingStandard.PHP.ReferenceSpacing"/>
<!--<rule ref="SlevomatCodingStandard.PHP.RequireExplicitAssertion"/>-->
<rule ref="SlevomatCodingStandard.PHP.RequireNowdoc"/>
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
<rule ref="SlevomatCodingStandard.Strings.DisallowVariableParsing"/>
<!--<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/>-->
<!--<rule ref="SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax"/>-->
<!--<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint"/>-->
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat"/>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
<rule ref="SlevomatCodingStandard.Variables.DisallowVariableVariable"/>
<!--<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable"/>-->
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable">
<properties>
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
<rule ref="SlevomatCodingStandard.Whitespaces.DuplicateSpaces">
<properties>
<property name="ignoreSpacesBeforeAssignment" value="true"/>
<property name="ignoreSpacesInAnnotation" value="true"/>
</properties>
</rule>
</ruleset>
15 changes: 5 additions & 10 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon

parameters:

paths:
- src
- tests

# The level 8 is the highest level
level: 5
# The level 9 is the highest level
level: 8

# ignoreErrors:
# - '#PHPDoc tag @var#'
#
# excludePaths:
# - ./*/*/FileToBeExcluded.php

checkMissingIterableValueType: false
excludePaths:
- ./tests/Stubs/**
Loading

0 comments on commit b62517f

Please sign in to comment.