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 13, 2023
1 parent 6fae455 commit e24af05
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Gettingstarted/Tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Open the report, with a web browser: it is located in projects/sculpin/diplomat.
Congratulations, this is your first audit.


.. _in-code-auditing-local:

In Code Auditing With Exakat (Local)
----------------------------------------

Expand Down Expand Up @@ -116,6 +118,9 @@ This command runs the default configuration over the code source. It displays im

Congratulations, this is your first audit.


.. _in-code-auditing-docker:

In Code Auditing With Exakat (Docker)
----------------------------------------

Expand Down
41 changes: 26 additions & 15 deletions Reference/Rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16848,26 +16848,34 @@ _____

.. _structures-couldusenullableoperator:

.. _could-use-nullable-object-operator:
.. _could-use-null-safe-object-operator:

Could Use Nullable Object Operator
++++++++++++++++++++++++++++++++++
Could Use Null-Safe Object Operator
+++++++++++++++++++++++++++++++++++

When the previous call may end up as null, the null-safe object operator will prevent fatal errors.
When the preceding function call has the potential to return null, employing the null-safe object operator can help mitigate fatal errors.

One approach is to assess the returned value prior to utilization, ensuring it is not null, and refraining from invoking methods on a null reference. Alternatively, the null-safe operator can be employed, allowing verification of the end `result <https://www.php.net/result>`_. If the `result <https://www.php.net/result>`_ is null, it indicates an `error <https://www.php.net/error>`_.

.. code-block:: php

<?php

// direct, uncertain usage
// direct usage, with a check on the final value
$a = foo()?->b() ?? throw new exception('something went wrong when calculating $a');
// throw as an expression is a PHP 8.0 code


// direct usage, may yield a Fatal error
foo()->b();

// indirect usage, with a check on the returned value
$a = foo();
$c = $a ? $a->b() : null;


function foo() : ?A {
return new A();
return rand(0, 1) ? new A() : null;
}

class A {
Expand All @@ -16882,9 +16890,9 @@ See also `PHP 8.0 feature focus: nullsafe methods <https://platform.sh/blog/2020
Suggestions
___________

* Add a test before using the return value
* Add a check on NULL before using the returned value
* Update the previous method to prevent it from returning null
* Use the null-safe object operator
* Use the null-safe object operator and test the result afterward



Expand Down Expand Up @@ -97846,7 +97854,7 @@ List of analyzers, by version of introduction, newest to oldest. In parenthesis,
* :ref:`Argument Could Be Iterable <argument-could-be-iterable>`
* :ref:`Check Division By Zero <check-division-by-zero>`
* :ref:`Checks Property Existence <checks-property-existence>`
* :ref:`Could Use Nullable Object Operator <could-use-nullable-object-operator>`
* :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`
* :ref:`Getter And Setter <getter-and-setter>`
* :ref:`Intersection Typehint <intersection-typehint>`
* :ref:`Recycled Variables <recycled-variables>`
Expand Down Expand Up @@ -101303,6 +101311,7 @@ Directory by PHP Function
+ :ref:`Constant Typo Looks Like A Variable <constant-typo-looks-like-a-variable>`
+ :ref:`Converted Exceptions <converted-exceptions>`
+ :ref:`Could Be Callable <could-be-callable>`
+ :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`
+ :ref:`Could Use Try <could-use-try>`
+ :ref:`Crypto Usage <crypto-usage>`
+ :ref:`Declare strict_types Usage <declare-strict\_types-usage>`
Expand Down Expand Up @@ -101468,6 +101477,7 @@ Directory by PHP Function
+ :ref:`Collect Methods Throwing Exceptions <collect-methods-throwing-exceptions>`
+ :ref:`Collect Throw Calls <collect-throw-calls>`
+ :ref:`Converted Exceptions <converted-exceptions>`
+ :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`
+ :ref:`Defined Exceptions <defined-exceptions>`
+ :ref:`Empty Classes <empty-classes>`
+ :ref:`Exception Order <exception-order>`
Expand Down Expand Up @@ -103405,7 +103415,7 @@ Directory by PHP Function
+ :ref:`Constant Typo Looks Like A Variable <constant-typo-looks-like-a-variable>`
+ :ref:`Could Be Null <could-be-null>`
+ :ref:`Could Be Ternary <could-be-ternary>`
+ :ref:`Could Use Nullable Object Operator <could-use-nullable-object-operator>`
+ :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`
+ :ref:`Could Use array_fill_keys <could-use-array\_fill\_keys>`
+ :ref:`Cyclic References <cyclic-references>`
+ :ref:`Default Then Discard <default-then-discard>`
Expand Down Expand Up @@ -104225,6 +104235,7 @@ Directory by PHP Function
+ :ref:`Collect Classes Dependencies <collect-classes-dependencies>`
+ :ref:`Compared Comparison <compared-comparison>`
+ :ref:`Constant Scalar Expressions <constant-scalar-expressions>`
+ :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`
+ :ref:`Crc32() Might Be Negative <crc32()-might-be-negative>`
+ :ref:`Don't Echo Error <don't-echo-error>`
+ :ref:`Don't Unset Properties <don't-unset-properties>`
Expand Down Expand Up @@ -107332,12 +107343,12 @@ Exakat links each rules to PHP features.

+ Null Safe Object Operator

+ :ref:`Could Use Nullable Object Operator <could-use-nullable-object-operator>`
+ :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`

+ Nullable

+ :ref:`Could Be Null <could-be-null>`
+ :ref:`Could Use Nullable Object Operator <could-use-nullable-object-operator>`
+ :ref:`Could Use Null-Safe Object Operator <could-use-null-safe-object-operator>`
+ :ref:`Hidden Nullable Typehint <hidden-nullable-typehint>`
+ :ref:`Use Nullable Type <use-nullable-type>`

Expand Down Expand Up @@ -108394,9 +108405,9 @@ Exakat helps reduce the amount of error and warning that code is producing by re
* :ref:`Argument must be of type int, array given <wrong-parameter-type>`
* :ref:`Array and string offset access syntax with curly braces is deprecated <no-more-curly-arrays>`
* :ref:`Attempt to echo a string that might be tainted <extensions-exttaint>`
* :ref:`Attempt to read property "b" on null <could-use-nullable-object-operator>`
* :ref:`Attempt to read property "b" on null <could-use-null-safe-object-operator>`
* :ref:`Attribute "AttributeFunction" cannot target Class (allowed targets: Function) <wrong-attribute-configuration>`
* :ref:`Call to a member function b() on null <could-use-nullable-object-operator>`
* :ref:`Call to a member function b() on null <could-use-null-safe-object-operator>`
* :ref:`Call to a member function m() on null <use-nullsafe-operator>`
* :ref:`Call to private Y\:\:__construct() from invalid context <can't-instantiate-class>`
* :ref:`Call to protected method x\:\:method <access-protected-structures>`
Expand Down Expand Up @@ -108452,7 +108463,7 @@ Exakat helps reduce the amount of error and warning that code is producing by re
* :ref:`Cannot use parent when current class scope has no parent <class-without-parent>`
* :ref:`Cannot use positional argument after argument unpacking <named-argument-and-variadic>`
* :ref:`Case-insensitive constants are deprecated. The correct casing for this constant is "A" <constant-case-preference>`
* :ref:`Class "null" not found <could-use-nullable-object-operator>`
* :ref:`Class "null" not found <could-use-null-safe-object-operator>`
* :ref:`Class 'PARENT' not found <use-lower-case-for-parent,-static-and-self>`
* :ref:`Class 'x' not found <undefined-class>`
* :ref:`Class BA contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (A\:\:aFoo) <abstract-or-implements>`
Expand Down
4 changes: 2 additions & 2 deletions Reference/Rulesets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ Total : 1601 analysis
* :ref:`variable-anf-property-typehint`
* :ref:`extends-stdclass`
* :ref:`scope-resolution-operator`
* :ref:`could-use-nullable-object-operator`
* :ref:`could-use-null-safe-object-operator`
* :ref:`cant-overload-constants`
* :ref:`variable-is-a-local-constant`
* :ref:`argument-could-be-iterable`
Expand Down Expand Up @@ -5795,7 +5795,7 @@ Total : 123 analysis
* :ref:`no-static-variable-in-a-method`
* :ref:`declare-static-once`
* :ref:`could-use-match`
* :ref:`could-use-nullable-object-operator`
* :ref:`could-use-null-safe-object-operator`
* :ref:`argument-could-be-iterable`
* :ref:`multiple-similar-calls`
* :ref:`could-be-ternary`
Expand Down

0 comments on commit e24af05

Please sign in to comment.