Conditions | 10 |
Paths | 11 |
Total Lines | 47 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
21 | public function render(Formatter $formatter, array $schema, string $role): ?string |
||
22 | { |
||
23 | if (! isset($schema[$this->property])) { |
||
24 | return null; |
||
25 | } |
||
26 | |||
27 | $listeners = (array)($schema[$this->property] ?? []); |
||
28 | |||
29 | if ($listeners === []) { |
||
30 | return null; |
||
31 | } |
||
32 | |||
33 | $rows = [ |
||
34 | \sprintf('%s:', $formatter->title($this->title)), |
||
35 | ]; |
||
36 | |||
37 | foreach ($listeners as $definition) { |
||
38 | $data = (array)$definition; |
||
39 | |||
40 | // Listener class |
||
41 | $class = \is_string($data[0] ?? null) |
||
42 | ? $formatter->typecast($data[0]) |
||
43 | : $formatter->error('undefined'); |
||
44 | $rows[] = \sprintf('%s%s', $formatter->title(' '), $class); |
||
45 | |||
46 | // Listener arguments |
||
47 | $args = $data[1] ?? null; |
||
48 | if ($args === null) { |
||
49 | continue; |
||
50 | } |
||
51 | if (\is_array($args)) { |
||
52 | foreach ($args as $key => $value) { |
||
53 | $row = $formatter->title(' ') . ' - '; |
||
54 | if (\is_string($key)) { |
||
55 | $row .= $formatter->property($key) . ' : '; |
||
56 | } |
||
57 | $row .= $formatter->info($this->printValue($value, $formatter)); |
||
58 | $rows[] = $row; |
||
59 | } |
||
60 | } elseif (is_string($args)) { |
||
61 | $rows[] = $formatter->title(' ') . ' - ' . $formatter->info($this->printValue($args, $formatter)); |
||
62 | } else { |
||
63 | $rows[] = $formatter->typecast($this->printValue($data, $formatter)); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | return \implode($formatter::LINE_SEPARATOR, $rows); |
||
68 | } |
||
86 |