1.2.1202. Too Many Chained Calls

Report chained calls of functions, methods and static methods are crammed in one expression.

This makes the whole expression difficult to read, and it is possible to miss some important parameter or intermidate calls when reviewing it.

This may lead to bugs when some of the intermediate calls may return an invalid result, such as null or false in case of error. Those must be tested before being propagated.

<?php

//
$s = strtoupper(hash('whirlpool',hash('sha1', microtime(true).crypt(uniqid(rand(), true)))));

?>

1.2.1202.1. Suggestions

  • Reduce the number of needed calls in the expression

  • Add intermediate checks on the values

  • Split the expression on multiple lines, and add a comment with a summary first

1.2.1202.2. Specs

Short name

Structures/TooManyChainedCalls

Rulesets

All, Changed Behavior, Semantics

Exakat since

2.5.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud