Skip to content

Commit

Permalink
Modify rule S1781: add drupal conventions support (#4132)
Browse files Browse the repository at this point in the history
  • Loading branch information
rudy-regazzoni-sonarsource authored Aug 9, 2024
1 parent f4259f2 commit 78f32ca
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rules/S1781/php/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This allows for more flexibility and ease of use when writing code.
However, it is generally recommended to follow a consistent casing convention for readability and maintainability purposes.
Relevant constants are `true`, `false` and `null`.

Note that if the Drupal framework is detected, this rule will enforce Drupal standards instead. Relevant constants are `TRUE`, `FALSE` and `NULL`.


=== Noncompliant code example

Expand All @@ -14,6 +16,13 @@ Relevant constants are `true`, `false` and `null`.
<?php ECHO 'Hello World'; ?>
----

[source,php,diff-id=2,diff-type=noncompliant]
----
<?php
// In a Drupal context
const CACHE_ENABLED = true;
?>
----

=== Compliant solution

Expand All @@ -22,10 +31,20 @@ Relevant constants are `true`, `false` and `null`.
<?php echo 'Hello World'; ?>
----

[source,php,diff-id=2,diff-type=compliant]
----
<?php
// In a Drupal context
const CACHE_ENABLED = TRUE;
?>
----

== Resources

=== Documentation
* https://www.php.net/manual/en/reserved.constants.php[PHP Manual - Predefined Constants]

* https://www.php.net/manual/en/reserved.constants.php[PHP Manual - Predefined Constants]
* https://www.drupal.org/docs/develop/standards/php/php-coding-standards#s-constants[Drupal - Naming Conventions - Constants]

ifdef::env-github,rspecator-view[]

Expand Down

0 comments on commit 78f32ca

Please sign in to comment.