Skip to content

Commit

Permalink
Version with sitemap for cobblers
Browse files Browse the repository at this point in the history
  • Loading branch information
christopheexakat committed Dec 19, 2023
1 parent 7b25137 commit 5aece44
Show file tree
Hide file tree
Showing 1,625 changed files with 105,201 additions and 98,519 deletions.
100,143 changes: 1,624 additions & 98,519 deletions Reference/Rules.rst

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions Reference/Rules/Arrays/AmbiguousKeys.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.. _arrays-ambiguouskeys:

.. _ambiguous-array-index:

Ambiguous Array Index
+++++++++++++++++++++

Indexes should not be defined with different types than int or string.

Array indices only accept integers and strings, so any other type of literal is reported. In fact, ``null`` is turned into an empty string, booleans are turned into an integer, and real numbers are truncated (not rounded).


.. code-block:: php
<?php
$x = [ 1 => 1,
'1' => 2,
1.0 => 3,
true => 4];
// $x only contains one element : 1 => 4
// Still wrong, immediate typecast to 1
$x[1.0] = 5;
$x[true] = 6;
?>
They are indeed distinct, but may lead to confusion.

See also `array <https://www.php.net/manual/en/language.types.array.php>`_.


Suggestions
___________

* Only use string or integer as key for an array.
* Use transtyping operator (string) and (int) to make sure of the type




Specs
_____

+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Short name | Arrays/AmbiguousKeys |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`Analyze <ruleset-Analyze>`, :ref:`Semantics <ruleset-Semantics>` |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 0.8.4 |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| PHP Version | All |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Severity | Minor |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Precision | High |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Features | array |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Examples | :ref:`case-prestashop-arrays-ambiguouskeys`, :ref:`case-mautic-arrays-ambiguouskeys` |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Available in | `Entreprise Edition <https://www.exakat.io/entreprise-edition>`_, `Exakat Cloud <https://www.exakat.io/exakat-cloud/>`_ |
+--------------+-------------------------------------------------------------------------------------------------------------------------+


33 changes: 33 additions & 0 deletions Reference/Rules/Arrays/AppendAndAssignArrays.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _arrays-appendandassignarrays:

.. _append-and-assign-arrays:

Append And Assign Arrays
++++++++++++++++++++++++

This rule reports arrays that are used both with append and direct index assignation. Read access are not considered here.

Array append and direct index assignation have different impact one on the other. In particular, assign a value explicitely and later append values may have an impact on one another.

Specs
_____

+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Short name | Arrays/AppendAndAssignArrays |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`Analyze <ruleset-Analyze>` |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 2.6.1 |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| PHP Version | All |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Severity | Minor |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Precision | High |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Available in | `Entreprise Edition <https://www.exakat.io/entreprise-edition>`_, `Exakat Cloud <https://www.exakat.io/exakat-cloud/>`_ |
+--------------+-------------------------------------------------------------------------------------------------------------------------+


71 changes: 71 additions & 0 deletions Reference/Rules/Arrays/ArrayBracketConsistence.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.. _arrays-arraybracketconsistence:

.. _array()---[--]-consistence:

Array() / [ ] Consistence
++++++++++++++++++++++++++

`array() <https://www.php.net/array>`_ or [ ] is the favorite.

`array() <https://www.php.net/array>`_ and [ ] have the same functional use.

The analyzed code has less than 10% of one of them : for consistency reasons, it is recommended to make them all the same.

It happens that `array() <https://www.php.net/array>`_ or [] are used depending on coding style and files. One file may be consistently using `array() <https://www.php.net/array>`_, while the others are all using [].



The only drawback to use [] over `array() <https://www.php.net/array>`_ is backward incompatibility.

.. code-block:: php
<?php
$a = array(1, 2);
$b = array(array(3, 4), array(5, 6));
$c = array(array(array(7, 8), array(9, 10)), array(11, 12), array(13, 14)));
// be consistent
$d = [1, 3];
?>
+-------------+---------+---------+-------------------------------------------------------------------------------------------+
| Name | Default | Type | Description |
+-------------+---------+---------+-------------------------------------------------------------------------------------------+
| array_ratio | 10 | integer | Percentage of arrays in one of the syntaxes, to trigger the other syntax as a violation. |
+-------------+---------+---------+-------------------------------------------------------------------------------------------+



Suggestions
___________

* Use one syntax consistently.




Specs
_____

+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Short name | Arrays/ArrayBracketConsistence |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`Preferences <ruleset-Preferences>` |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 0.8.9 |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| PHP Version | All |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Severity | Minor |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | Slow (1 hour) |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Precision | High |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Features | array |
+--------------+-------------------------------------------------------------------------------------------------------------------------+
| Available in | `Entreprise Edition <https://www.exakat.io/entreprise-edition>`_, `Exakat Cloud <https://www.exakat.io/exakat-cloud/>`_ |
+--------------+-------------------------------------------------------------------------------------------------------------------------+


51 changes: 51 additions & 0 deletions Reference/Rules/Arrays/ArrayNSUsage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. _arrays-arraynsusage:

.. _short-syntax-for-arrays:

Short Syntax For Arrays
+++++++++++++++++++++++

Arrays written with the new short syntax.

PHP 5.4 introduced the new short syntax, with square brackets. The previous syntax, based on the `array() <https://www.php.net/array>`_ keyword is still available.


.. code-block:: php
<?php
// All PHP versions array
$a = array(1, 2, 3);
// PHP 5.4+ arrays
$a = [1, 2, 3];
?>
See also `Array <https://www.php.net/manual/en/language.types.array.php>`_.


Specs
_____

+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Short name | Arrays/ArrayNSUsage |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`Appinfo <ruleset-Appinfo>`, :ref:`CE <ruleset-CE>`, :ref:`CompatibilityPHP53 <ruleset-CompatibilityPHP53>` |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 0.8.4 |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PHP Version | With PHP 5.3 and more recent |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Severity | Critical |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Precision | Very high |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Features | array |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Available in | `Entreprise Edition <https://www.exakat.io/entreprise-edition>`_, `Community Edition <https://www.exakat.io/community-edition>`_, `Exakat Cloud <https://www.exakat.io/exakat-cloud/>`_ |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


47 changes: 47 additions & 0 deletions Reference/Rules/Arrays/Arrayindex.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. _arrays-arrayindex:

.. _array-index:

Array Index
+++++++++++

List of all indexes used in arrays.


.. code-block:: php
<?php
// Index
$x['index'] = 1;
// in array creation
$a = array('index2' => 1);
$a2 = ['index3' => 2];
?>
Specs
_____

+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Short name | Arrays/Arrayindex |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`Appinfo <ruleset-Appinfo>`, :ref:`CE <ruleset-CE>` |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 0.8.4 |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PHP Version | All |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Severity | |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Precision | High |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Features | array |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Available in | `Entreprise Edition <https://www.exakat.io/entreprise-edition>`_, `Community Edition <https://www.exakat.io/community-edition>`_, `Exakat Cloud <https://www.exakat.io/exakat-cloud/>`_ |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


0 comments on commit 5aece44

Please sign in to comment.