Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294415

[meta] Introduce PHPStan Strict Rules

$
0
0

Problem/Motivation

This issue resolves to discuss the introduction of PHPStan Strict Rules into Drupal.

PHPStan Strict are a set of configuration chances and extra rules that encourage defensive programming. Things that could even remotely result in a bug are prevented. Think alongside: not relying on magical features of a programming language when writing code for the space shuttle. Being explicit, especially in regards to typing.

PHPStan strict can be introduced to a project simply by adding the dependency, and relying on phpstan/extension-installer to add it in.

Introducing the project will cause PHPStan to generate a lot of new messages. Rather than add all the new messages to the baseline, you can turn off all rules by default (as mentioned on strict rules Github project page):

parameters:
	strictRules:
		disallowedLooseComparison: false
		booleansInConditions: false
		uselessCast: false
		requireParentConstructorCall: false
		disallowedBacktick: false
		disallowedEmpty: false
		disallowedImplicitArrayCreation: false
		disallowedShortTernary: false
		overwriteVariablesWithLoop: false
		closureUsesThis: false
		matchingInheritedMethodNames: false
		numericOperandsInArithmeticOperators: false
		strictFunctionCalls: false
		dynamicCallOnStaticMethod: false
		switchConditionsMatchingType: false
		noVariableVariables: false
		strictArrayFilter: false
		illegalConstructorMethodCall: false

After adding this rule-disabling configuration, there will still be quite a few error messages. These messages are caused by configuration changes enforced by strict-rules.

These remaining issues are typically quite straightforward to resolve. I've already created a meta issue and a series of child issues over at #3487269: [meta] Resolve issues exposed by PHPStan Strict with all rules off (misc and core configuration changes). As you can see in the associated MR's, the code changes are quite obviously bugs/typos/potential logic issues. I wouldn't say we need to even consider including Strict-Rules in order to resolve those.

Proposed resolution

Introducing Strict-rules does not interfere with the ongoing (fantastic) initiative of resolving traditional PHPStan Levels. Strict rules can run in parallel.

My suggested order of operations is:

Remaining tasks

Discuss above, in parallel resolve #3487269: [meta] Resolve issues exposed by PHPStan Strict with all rules off (misc and core configuration changes)


Viewing all articles
Browse latest Browse all 294415

Trending Articles