| Conditions | 5 |
| Paths | 5 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 30 | public function process(array $keysIndex): array |
||
| 31 | { |
||
| 32 | $el = []; |
||
| 33 | foreach ($this->schema as $key => $value) { |
||
| 34 | if (preg_match('/{.+}/', $value)) { |
||
| 35 | if (preg_match('/{data\.(.+)}/s', $value, $matches)) { |
||
| 36 | $el[$key] = $this->faker->randomElement($keysIndex[$matches[1]]); |
||
|
|
|||
| 37 | continue; |
||
| 38 | } |
||
| 39 | |||
| 40 | $method = str_replace(['{', '}'], '', $value); |
||
| 41 | $re = '/{(.*)\((.*)\)}/s'; |
||
| 42 | $str = $value; |
||
| 43 | |||
| 44 | preg_match_all($re, $str, $matches, PREG_SET_ORDER); |
||
| 45 | |||
| 46 | if ($matches === []) { |
||
| 47 | $el[$key] = $this->faker->{$method}; |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | $method = $matches[0][1]; |
||
| 52 | $params = json_decode($matches[0][2], true); |
||
| 53 | $el[$key] = $this->faker->{$method}(...$params); |
||
| 54 | continue; |
||
| 55 | } |
||
| 56 | |||
| 57 | $el[$key] = $value; |
||
| 58 | } |
||
| 59 | |||
| 60 | return $el; |
||
| 61 | } |
||
| 62 | } |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.