Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:php-code-style/single-var-declaration
Language: PHP
Severity: Notice
Category: Best Practices
Description
This rule requires that each variable declaration should be on its own separate line. This is important for readability and maintainability of the code. If multiple variables are declared on the same line, it can be easy to miss a declaration or confuse the values of the variables.
In order to comply with this rule, when declaring multiple variables, each one should be placed on its own line with its own assignment statement. This makes it clear what each variable is and what its initial value is.
Non-compliant code can be corrected by moving each declaration to its own line. For example, instead of writing $field1 = 1, $field2 = 2;, you can write: $field1 = 1; $field2 = 2;. This makes the code easier to read and understand.
Non-Compliant Code Examples
<?phpclassTest{$field1=1,$field2=2;}
Compliant Code Examples
<?phpclassTest{$field1=1;$field2=2;}
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- php-code-style # Rules to enforce PHP code style.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines