1.2.644. Long Arguments

Long arguments should be put in variable, to preserve readability.

When literal arguments are too long, they break the hosting structure by moving the next argument too far on the right. Whenever possible, long arguments should be set in a local variable to keep the readability. Literal strings and heredoc strings, including variables, that are over 50 chars longs are reported here.

<?php

// Now the call to foo() is easier to read.
$reallyBigNumber = <<<BIGNUMBER
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
BIGNUMBER
foo($reallyBigNumber, 2, '12345678901234567890123456789012345678901234567890');

// where are the next arguments ?
foo('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890', 2, '123456789012345678901234567890123456789012345678901234567890');

// This is still difficult to read
foo(<<<BIGNUMBER
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
BIGNUMBER
, 2, '123456789012345678901234567890123456789012345678901234567890');

?>

Name

Default

Type

Description

codeTooLong

100

integer

Minimum size of a functioncall or a methodcall to be considered too long.

1.2.644.1. Suggestions

  • Put the long arguments in a separate variable, and use the variable in the second expression, reducing its total length

1.2.644.2. Specs

Short name

Structures/LongArguments

Rulesets

All, Analyze

Exakat since

0.9.7

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

argument

Examples

Cleverstyle, Contao

Available in

Entreprise Edition, Exakat Cloud