| Conditions | 1 |
| Paths | 1 |
| Total Lines | 19 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 0 | ||
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 53 | public function __construct( |
||
| 54 | string $name, |
||
| 55 | Table $table, |
||
| 56 | array $keymap, |
||
| 57 | bool $many = false, |
||
| 58 | Table $pivot = null, |
||
| 59 | array $pivot_keymap = null, |
||
| 60 | string $sql = null, |
||
| 61 | array $par = null |
||
| 62 | ) { |
||
| 63 | $this->name = $name; |
||
| 64 | $this->table = $table; |
||
| 65 | $this->keymap = $keymap; |
||
| 66 | $this->many = $many; |
||
| 67 | $this->pivot = $pivot; |
||
| 68 | $this->pivot_keymap = $pivot_keymap; |
||
|
|
|||
| 69 | $this->sql = $sql; |
||
| 70 | $this->par = $par; |
||
| 71 | } |
||
| 72 | } |
||
| 73 |
Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.
To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.
The function can be called with either null or an array for the parameter
$needlebut will only accept an array as$haystack.