rspec/rules/S1781/php/rule.adoc

61 lines
1.5 KiB
Plaintext

== Why is this an issue?
In PHP, keywords and constants are case-insensitive, meaning they can be written in either lower case or upper case without affecting their functionality.
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
[source,php,diff-id=1,diff-type=noncompliant]
----
<?php ECHO 'Hello World'; ?>
----
[source,php,diff-id=2,diff-type=noncompliant]
----
<?php
// In a Drupal context
const CACHE_ENABLED = true;
?>
----
=== Compliant solution
[source,php,diff-id=1,diff-type=compliant]
----
<?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.drupal.org/docs/develop/standards/php/php-coding-standards#s-constants[Drupal - Naming Conventions - Constants]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Write this "XXXX" [keyword|constant] in lower case.
endif::env-github,rspecator-view[]