Skip to content

Instantly share code, notes, and snippets.

@kiler129
Created July 19, 2020 21:03
Show Gist options
  • Save kiler129/fa80af4660c332897dacd23f735b5906 to your computer and use it in GitHub Desktop.
Save kiler129/fa80af4660c332897dacd23f735b5906 to your computer and use it in GitHub Desktop.
PHP Code Quality
{
"type": "project",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable" : true,
"require": {
"php-64bit": "^7.4.0"
},
"require-dev": {
"object-calisthenics/phpcs-calisthenics-rules": "^3.7",
"phpstan/phpstan": "^0.12.22",
"phpstan/phpstan-deprecation-rules": "^0.12.2",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpstan/phpstan-symfony": "^0.12.6",
"roave/security-advisories": "dev-master",
"slevomat/coding-standard": "^6.3",
"sllh/composer-versions-check": "^2.0",
"squizlabs/php_codesniffer": "^3.5"
},
"scripts": {
"check-code-quality": [
"vendor/bin/phpcs --standard=phpcs.xml.dist --extensions=php ./src",
"vendor/bin/phpstan analyse src -c phpstan.src.neon"
],
"fix-cs": [
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
],
"lint": [
"@composer validate --strict",
"bin/console lint:yaml config/"
]
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
}
}
<?xml version="1.0"?>
<ruleset name="Project CS" namespace="">
<config name="installed_paths" value="../../object-calisthenics/phpcs-calisthenics-rules/src,../../slevomat/coding-standard"/>
<ini name="memory_limit" value="128M"/>
<arg name="colors"/>
<arg name="basepath" value="."/>
<arg name="parallel" value="8" />
<autoload>./vendor/autoload.php</autoload>
<file>src</file>
<file>tests</file>
<exclude-pattern>*/src/DependencyInjection/Configuration\.php</exclude-pattern>
<!-- Don't hide tokenizer exceptions -->
<rule ref="Internal.Tokenizer.Exception">
<type>error</type>
</rule>
<rule ref="PSR2"/>
<!-- ############################################################################ -->
<!-- PHPCS built-in rules -->
<!-- ############################################################################ -->
<rule ref="Generic.Files.LineLength.TooLong" />
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<!-- Use proper logging facilities -->
<element key="echo" value="null"/>
<element key="print" value="null"/>
<element key="is_null" value="null"/> <!-- Use "$x === null" instead -->
<element key="die" value="null"/> <!-- Replace by proper code return or exception -->
<element key="create_function" value="null"/> <!-- Deprecated, use lambdas -->
<element key="eval" value="null"/> <!-- Does this need a comment? -->
<element key="goto" value="null"/> <!-- https://xkcd.com/292/ -->
<element key="define" value="null"/> <!-- Use const keyword -->
<!-- Use proper syntax -->
<element key="extract" value="null"/>
<element key="call_user_func" value="null"/>
<element key="call_user_func_array" value="null"/>
</property>
</properties>
</rule>
<rule ref="Generic.Metrics.CyclomaticComplexity">
<properties>
<property name="complexity" value="15" />
<property name="absoluteComplexity" value="15" />
</properties>
</rule>
<rule ref="Generic.Metrics.NestingLevel" />
<rule ref="Generic.Metrics.NestingLevel" />
<!-- ############################################################################ -->
<!-- Sourced from https://github.com/object-calisthenics/phpcs-calisthenics-rules -->
<!-- ############################################################################ -->
<rule ref="ObjectCalisthenics.Metrics.MaxNestingLevel">
<properties>
<property name="maxNestingLevel" value="3"/>
</properties>
</rule>
<rule ref="ObjectCalisthenics.ControlStructures.NoElse" />
<rule ref="ObjectCalisthenics.NamingConventions.ElementNameMinimalLength">
<properties>
<property name="minLength" value="3"/>
<!--
i - iteration
id - self explanatory
to - from/to are obvious
k,v - key/value, very common
e,t - common in catch for $e(xception) or $t(hrowable)
_ - common convention to mark variable as not used in loops (e.g. foreach ($foo as $key => $_))
-->
<property name="allowedShortNames" type="array" value="i,id,to,k,v,e,t,_"/>
</properties>
</rule>
<rule ref="ObjectCalisthenics.Files.ClassTraitAndInterfaceLength">
<properties>
<property name="maxLength" value="300"/>
</properties>
</rule>
<rule ref="ObjectCalisthenics.Files.FunctionLength">
<properties>
<property name="maxLength" value="80"/>
</properties>
</rule>
<rule ref="ObjectCalisthenics.Metrics.PropertyPerClassLimit">
<properties>
<property name="maxCount" value="10"/>
</properties>
</rule>
<rule ref="ObjectCalisthenics.Metrics.MethodPerClassLimit">
<properties>
<property name="maxCount" value="10"/>
</properties>
</rule>
<!-- ############################################################################ -->
<!-- Sourced from https://github.com/slevomat/coding-standard -->
<!-- ############################################################################ -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<properties>
<property name="enableObjectTypeHint" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableNativeTypeHint" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<property name="enableObjectTypeHint" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint" />
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="spacesCountAroundEqualsSign" value="0" />
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation" />
<!-- <rule ref="SlevomatCodingStandard.Classes.ClassStructure">-->
<!-- //TODO: configure me according to PSR https://github.com/slevomat/coding-standard#slevomatcodingstandardclassesclassstructure- -->
<!-- </rule>-->
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding" />
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition" />
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch" />
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEmpty" /> <!-- I love it for arrays... but... it's crap -->
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator" />
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit">
<properties>
<property name="ignoreStandaloneIfInScope" value="true" />
<property name="ignoreOneLineTrailingIf" value="true" />
<property name="ignoreTrailingIfWithOneInstruction" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Functions.StrictCall" />
<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
<rule ref="SlevomatCodingStandard.PHP.DisallowDirectMagicInvokeCall" /> <!-- no magic methods should be called directly... -->
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators" />
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator" />
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements" /> <!-- has options, none used now -->
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
<rule ref="SlevomatCodingStandard.Functions.UnusedParameter" />
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue" />
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace" />
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias" />
<rule ref="SlevomatCodingStandard.PHP.DisallowReference" /> <!-- objects should be used instead when such behavior is desired -->
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses" />
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking" />
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon" />
<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable" />
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable" />
<rule ref="SlevomatCodingStandard.Variables.UselessVariable">
<properties>
<property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch" />
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma" />
<rule ref="SlevomatCodingStandard.Classes.ClassMemberSpacing">
<properties>
<property name="linesCountBetweenMembers" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.ConstantSpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1" />
<property name="maxLinesCountBeforeWithComment" value="2" />
<property name="minLinesCountBeforeWithoutComment" value="0" />
<property name="maxLinesCountBeforeWithoutComment" value="2" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition" /> <!-- this makes a hot mess in git -->
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiPropertyDefinition" /> <!-- this makes a hot mess in git -->
<rule ref="SlevomatCodingStandard.Classes.MethodSpacing">
<properties>
<property name="minLinesCount" value="1" />
<property name="maxLinesCount" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference" />
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing">
<properties>
<property name="minLinesCountBeforeWithComment" value="1" />
<property name="maxLinesCountBeforeWithComment" value="2" />
<property name="minLinesCountBeforeWithoutComment" value="0" />
<property name="maxLinesCountBeforeWithoutComment" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature">
<properties>
<!-- I know PSR, we have wide screens ffs - 120 is STILL within the limits of the standard -->
<property name="minLineLength" value="120" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature">
<properties>
<property name="maxLineLength" value="80" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration" /> <!-- this makes a hot mess in git -->
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing">
<properties>
<property name="linesCountBeforeFirstUse" value="0" />
<property name="linesCountBeforeFirstUseWhenFirstInClass" value="0" />
<property name="linesCountBetweenUses" value="0" />
<property name="linesCountAfterLastUse" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses" />
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses" />
<rule ref="SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator" />
<rule ref="SlevomatCodingStandard.ControlStructures.RequireTernaryOperator">
<properties>
<property name="ignoreMultiLine" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison" />
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
<properties>
<property ref="spacesCountAfterKeyword" value="1" />
<property ref="spacesCountBeforeArrow" value="1" />
<property ref="spacesCountAfterArrow" value="1" />
<property ref="allowMultiLine" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction" />
<rule ref="SlevomatCodingStandard.Functions.RequireArrowFunction">
<properties>
<property name="allowNested" value="false" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="psr12Compatible" value="true" />
<property name="caseSensitive" value="false" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile" />
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration" />
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing">
<properties>
<property name="linesCountBeforeNamespace" value="1" />
<property name="linesCountAfterNamespace" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing">
<properties>
<property name="linesCountBeforeFirstUse" value="1" />
<property name="linesCountAfterLastUse" value="1" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Numbers.RequireNumericLiteralSeparator">
<properties>
<property name="enable" value="true" />
<property name="minDigitsBeforeDecimalPoint" value="5" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing">
<properties>
<property name="spacesCount" value="0" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing">
<properties>
<property name="spacesCountAfterOperator" value="0" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint" />
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints" />
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition" />
<rule ref="SlevomatCodingStandard.PHP.ShortList" />
<rule ref="SlevomatCodingStandard.PHP.TypeCast" />
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="0" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing" />
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing" />
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse" />
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants" />
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions" />
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine" />
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
<properties>
<property name="linesCountAfterOpeningBrace" value="0" />
<property name="linesCountBeforeClosingBrace" value="0" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property name="forbiddenAnnotations" type="array">
<element value="@author" />
<element value="@created" />
<element value="@version" />
<element value="@package" />
<element value="@copyright" />
<element value="@license" />
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment" />
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment" />
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment" />
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn" />
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator" />
</ruleset>
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
level: 7
tmpDir: var/cache/_phpstan
parallel:
jobSize: 20
maximumNumberOfProcesses: 16
minimumNumberOfJobsPerProcess: 2
processTimeout: 30.0
symfony:
container_xml_path: '%rootDir%/../../../var/cache/dev/NoFlash_SnmpBridge_KernelDevDebugContainer.xml'
console_application_loader: %rootDir%/../../../.tools/PhpStan/console-application.php
excludes_analyse:
- %rootDir%/../../../src/DependencyInjection/Configuration.php # semantic config will never work with static analysis
tipsOfTheDay: false
polluteScopeWithLoopInitialAssignments: false
polluteScopeWithAlwaysIterableForeach: false
polluteCatchScopeWithTryAssignments: true
checkAlwaysTrueCheckTypeFunctionCall: true
checkAlwaysTrueInstanceof: true
checkAlwaysTrueStrictComparison: true
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
checkMissingClosureNativeReturnTypehintRule: true
reportMaybesInMethodSignatures: true
reportStaticMethodSignatures: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
treatPhpDocTypesAsCertain: false
checkMissingIterableValueType: false # handled by PHPCs with more granularity
ignoreErrors:
# yay! nothing ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment