Skip to content

Commit

Permalink
version 2.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
christopheexakat committed Nov 6, 2023
1 parent b58dee1 commit fc019d3
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 51 deletions.
7 changes: 6 additions & 1 deletion Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ Here is the release note of exakat.
+

+ Analysis
+
+ New analysis : report arrays that are used for append and direct index access at the same time
+ New analysis : report get_class() and get_parent_class() without arguments
+ Updated analysis : Literal inventory now reports float, array() and heredocs
+ New analysis : report usage of advanced static variable initialisation
+ New analysis : cannot be readonly
+ New analysis : report triplet stats from the internal graph

+ Tokenizer
+
Expand Down
216 changes: 178 additions & 38 deletions Reference/Rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Rules
Introduction
------------------------

Exakat provides unique 1597 rules to detect BUGS, CODE SMELLS, SECURITY OR QUALITY ISSUES in your PHP code.
Exakat provides unique 1600 rules to detect BUGS, CODE SMELLS, SECURITY OR QUALITY ISSUES in your PHP code.

Each rule is documented with code example to allow you to remediate your code. If you want to automate remediation, ours cobblers can are there to fix the issues in your code for your.

Expand Down Expand Up @@ -628,7 +628,6 @@ _____
+++++++++

Usage of the short echo tab, ``<?=``, that echo's directly the following content.

<?= $variable;
?>

Expand Down Expand Up @@ -2410,6 +2409,39 @@ _____
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


.. _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>` |
+--------------+------------------------------+
| Exakat since | 2.6.1 |
+--------------+------------------------------+
| PHP Version | All |
+--------------+------------------------------+
| Severity | Minor |
+--------------+------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+------------------------------+
| Precision | High |
+--------------+------------------------------+
| Available in | |
+--------------+------------------------------+


.. _php-argon2usage:

.. _argon2-usage:
Expand Down Expand Up @@ -8898,6 +8930,31 @@ _____
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


.. _classes-cannotbereadonly:

Classes/CannotBeReadonly
++++++++++++++++++++++++

Specs
_____

+--------------+----------------------------------------------------------------------+
| Short name | Classes/CannotBeReadonly |
+--------------+----------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`Class Review <ruleset-Class-Review>` |
+--------------+----------------------------------------------------------------------+
| Exakat since | 2.6.1 |
+--------------+----------------------------------------------------------------------+
| Severity | Minor |
+--------------+----------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+----------------------------------------------------------------------+
| Precision | Unknown |
+--------------+----------------------------------------------------------------------+
| Available in | |
+--------------+----------------------------------------------------------------------+


.. _php-cloneconstant:

.. _clone-constant:
Expand Down Expand Up @@ -19571,6 +19628,7 @@ Deprecated PHP Functions
Note that these functions may be still usable : they generate warning that help tracking their usage in the log. To eradicate their usage, watch the logs, and update any deprecated warning. This way, the code won't be stuck when the function is actually removed from PHP.



.. code-block:: php

<?php
Expand Down Expand Up @@ -20922,7 +20980,26 @@ The global namespace is the default namespace, where all functions, classes, con

In particular, PHP native classes usually live in that namespace. By creating functions in that namespace, the code may encounter naming conflict, when the PHP group decides to use a name that the code also uses. This already happened in PHP version 5.1.1, where a ``Date`` native class was introduced, and had to be `disabled in the following minor version <https://www.php.net/ChangeLog-5.php#5.1.1>`_.

Nowadays, conflicts appear between components, which claim the same name.
Nowadays, conflicts appear between components, which claim the same name.



.. code-block:: php

<?php

// This is not polluting the global namespace
namespace My/Namespace {
class X {}
}

// This is polluting the global namespace
// It might be in conflict with PHP classes in the future
namespace {
class X {}
}

?>

See also `Using namespaces: fallback to global function/constant <https://www.php.net/manual/en/language.namespaces.fallback.php>`_.

Expand Down Expand Up @@ -40929,7 +41006,6 @@ Mistaken Concatenation

A unexpected structure is built for initialization. It may be a typo that creates an unwanted expression.


.. code-block:: php

<?php
Expand Down Expand Up @@ -54888,6 +54964,9 @@ PHP Overridden Function

Within the declaration namespace, it is easy to confuse the local version and the global version, unless the function has been prefixed with ``\``.

When a piece of code use overridden function, any newcomer may be confused by the usage of classic PHP native function in surprising situations.

It is recommended to avoid redeclare PHP native function in namespaces.

.. code-block:: php

Expand All @@ -54906,11 +54985,6 @@ Within the declaration namespace, it is easy to confuse the local version and th

?>


When a piece of code use overridden function, any newcomer may be confused by the usage of classic PHP native function in surprising situations.

It is recommended to avoid redeclare PHP native function in namespaces.

Suggestions
___________

Expand Down Expand Up @@ -66222,7 +66296,7 @@ _____
Single Use Variables
++++++++++++++++++++

Variables that are written, then read. Only used once.
This is the list of variables that are written, then read, and only used once.

Single-use variables may be trimmed down, and the initial expression may be used instead.

Expand All @@ -66249,6 +66323,7 @@ ___________

* Merge the two expressions into one larger
* Make a second use of the variable
* Inline the code of the expression instead of the variable



Expand Down Expand Up @@ -67396,6 +67471,51 @@ _____
+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


.. _variables-staticvariableinitialisation:

.. _static-variable-initialisation:

Static Variable Initialisation
++++++++++++++++++++++++++++++

`Static <https://www.php.net/manual/en/language.oop5.static.php>`_ variables can be initialized like any other variable, straight from the ``static`` keyword. This was added in PHP 8.3.

Indeed, `static <https://www.php.net/manual/en/language.oop5.static.php>`_ variables are variables, so they shall be initialized with any value, another variable or a functioncall. This behavior is different from the `static <https://www.php.net/manual/en/language.oop5.static.php>`_ constant expression, where only a small set of operators and constants can be used.


.. code-block:: php

<?php

function foo(int $a = 0) {
static $s = 1;

static $s2 = $a + 1;
}
?>

Specs
_____

+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Short name | Variables/StaticVariableInitialisation |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`CompatibilityPHP81 <ruleset-CompatibilityPHP81>`, :ref:`CompatibilityPHP82 <ruleset-CompatibilityPHP82>` |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Exakat since | 2.6.1 |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Severity | Minor |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Precision | Very high |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Features | static constant expression |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+
| Available in | |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------+


.. _variables-staticvariables:

.. _static-variables:
Expand Down Expand Up @@ -68443,33 +68563,6 @@ _____
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


.. _structures-getclasswithoutarg:

Structures/GetClassWithoutArg
+++++++++++++++++++++++++++++

Specs
_____

+--------------+-------------------------------+
| Short name | Structures/GetClassWithoutArg |
+--------------+-------------------------------+
| Rulesets | :ref:`All <ruleset-All>` |
+--------------+-------------------------------+
| Exakat since | 2.6.1 |
+--------------+-------------------------------+
| PHP Version | All |
+--------------+-------------------------------+
| Severity | Minor |
+--------------+-------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+-------------------------------+
| Precision | Unknown |
+--------------+-------------------------------+
| Available in | |
+--------------+-------------------------------+


.. _structures-substrtotrim:

.. _substr-to-trim:
Expand Down Expand Up @@ -96054,6 +96147,46 @@ _____
+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


.. _structures-getclasswithoutarg:

.. _get\_class()-without-argument:

get_class() Without Argument
++++++++++++++++++++++++++++

`get_class() <https://www.php.net/get_class>`_ and `get_parent_class() <https://www.php.net/get_parent_class>`_ should not be called without arguments. It was possible until PHP 8.3, but it is now a deprecated behavior.

Suggestions
___________

* Use get_called_class() instead
* Use __CLASS__ magic constant instead




Specs
_____

+--------------+----------------------------------------------------------------------------------+
| Short name | Structures/GetClassWithoutArg |
+--------------+----------------------------------------------------------------------------------+
| Rulesets | :ref:`All <ruleset-All>`, :ref:`CompatibilityPHP83 <ruleset-CompatibilityPHP83>` |
+--------------+----------------------------------------------------------------------------------+
| Exakat since | 2.6.1 |
+--------------+----------------------------------------------------------------------------------+
| PHP Version | With PHP 9.0 and older |
+--------------+----------------------------------------------------------------------------------+
| Severity | Minor |
+--------------+----------------------------------------------------------------------------------+
| Time To Fix | Quick (30 mins) |
+--------------+----------------------------------------------------------------------------------+
| Precision | Very high |
+--------------+----------------------------------------------------------------------------------+
| Available in | |
+--------------+----------------------------------------------------------------------------------+


.. _php-idnuts46:

.. _idn\_to\_ascii()-new-default:
Expand Down Expand Up @@ -97283,9 +97416,12 @@ List of analyzers, by version of introduction, newest to oldest. In parenthesis,

* 2.6.1

* :ref:`Append And Assign Arrays <append-and-assign-arrays>`
* :ref:`Classes/CannotBeReadonly <classes-cannotbereadonly>`
* :ref:`Favorite Casting Method <favorite-casting-method>`
* :ref:`Multiline Expressions <multiline-expressions>`
* :ref:`Structures/GetClassWithoutArg <structures-getclasswithoutarg>`
* :ref:`Static Variable Initialisation <static-variable-initialisation>`
* :ref:`get_class() Without Argument <get\_class()-without-argument>`

* 2.6.0

Expand Down Expand Up @@ -101646,6 +101782,7 @@ Directory by PHP Function
+ :ref:`No get_class() With Null <no-get\_class()-with-null>`
+ :ref:`Scope Resolution Operator <scope-resolution-operator>`
+ :ref:`Use This <use-this>`
+ :ref:`get_class() Without Argument <get\_class()-without-argument>`

+ `get_class_methods()`

Expand Down Expand Up @@ -101687,6 +101824,7 @@ Directory by PHP Function
+ `get_parent_class()`

+ :ref:`Use This <use-this>`
+ :ref:`get_class() Without Argument <get\_class()-without-argument>`

+ `get_resources()`

Expand Down Expand Up @@ -104149,6 +104287,7 @@ Directory by PHP Function
+ :ref:`Static Methods Called From Object <static-methods-called-from-object>`
+ :ref:`Static Methods Can't Contain $this <static-methods-can't-contain-$this>`
+ :ref:`Static Variable Can Default To Arbitrary Expression <static-variable-can-default-to-arbitrary-expression>`
+ :ref:`Static Variable Initialisation <static-variable-initialisation>`
+ :ref:`Used Once Variables (In Scope) <used-once-variables-(in-scope)>`
+ :ref:`Wrong Access Style to Property <wrong-access-style-to-property>`
+ :ref:`ext/reflection <ext-reflection>`
Expand Down Expand Up @@ -104607,6 +104746,7 @@ Directory by PHP Function
+ :ref:`Static Methods Can't Contain $this <static-methods-can't-contain-$this>`
+ :ref:`Static Properties <static-properties>`
+ :ref:`Static Variable Can Default To Arbitrary Expression <static-variable-can-default-to-arbitrary-expression>`
+ :ref:`Static Variable Initialisation <static-variable-initialisation>`
+ :ref:`Static Variables <static-variables>`
+ :ref:`Too Many Chained Calls <too-many-chained-calls>`
+ :ref:`Too Many Dereferencing <too-many-dereferencing>`
Expand Down

0 comments on commit fc019d3

Please sign in to comment.