Max Params

ID

php.max_params

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Complexity

Language

Php

Tags

complexity

Description

Reports a named function or method whose parameter count exceeds a configurable threshold (default 7). Closures and arrow functions are excluded, because their parameter list is usually fixed by the callback contract of whatever consumes them.

Rationale

A long parameter list is hard to call correctly: the argument order is easy to get wrong at the call site, optional arguments force long runs of repeated default values, and the sheer count is a strong signal that the function has accumulated several unrelated responsibilities. Grouping cohesive parameters into a small value object, or splitting the function, makes both the signature and the call sites easier to read and to change.

<?php
// FLAW — eight parameters, hard to call and likely doing too much
function buildReport($title, $from, $to, $format, $author, $footer, $watermark, $locale) {
    // ...
}

// OK — related options grouped into a single value object
function buildReport(ReportOptions $options) {
    // ...
}

Remediation

Group related parameters into a dedicated value object or settings class, or split the function into smaller functions each with a focused, short parameter list. Adjust the maxParams property if your project standard differs from the default.