| Conditions | 7 |
| Paths | 4 |
| Total Lines | 45 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function render(Formatter $formatter, array $schema, string $role): ?string |
||
| 14 | { |
||
| 15 | $rows = []; |
||
| 16 | |||
| 17 | $columns = $schema[SchemaInterface::COLUMNS] ?? []; |
||
| 18 | $title = \sprintf('%s:', $formatter->title('Fields')); |
||
| 19 | |||
| 20 | if (! \is_array($columns) || \count($columns) === 0) { |
||
| 21 | return $title . ' ' . $formatter->error('not defined'); |
||
| 22 | } |
||
| 23 | |||
| 24 | $padding = $formatter->title('') . ' '; |
||
| 25 | |||
| 26 | $rows[] = $title; |
||
| 27 | |||
| 28 | $rows[] = \sprintf( |
||
| 29 | '%s(%s -> %s -> %s)', |
||
| 30 | $padding, |
||
| 31 | $formatter->property('property'), |
||
| 32 | $formatter->column('db.field'), |
||
| 33 | $formatter->typecast('typecast') |
||
| 34 | ); |
||
| 35 | |||
| 36 | $types = $schema[SchemaInterface::TYPECAST] ?? []; |
||
| 37 | |||
| 38 | foreach ($columns as $property => $field) { |
||
| 39 | $typecast = $types[$property] ?? $types[$field] ?? null; |
||
| 40 | $row = \sprintf( |
||
| 41 | '%s%s -> %s', |
||
| 42 | $padding, |
||
| 43 | $formatter->property((string)$property), |
||
| 44 | $formatter->column($field) |
||
| 45 | ); |
||
| 46 | |||
| 47 | if ($typecast !== null && $typecast !== [] && $typecast !== '') { |
||
| 48 | $row .= \sprintf( |
||
| 49 | ' -> %s', |
||
| 50 | $formatter->typecast(\implode('::', (array)$typecast)) |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | |||
| 54 | $rows[] = $row; |
||
| 55 | } |
||
| 56 | |||
| 57 | return \implode($formatter::LINE_SEPARATOR, $rows); |
||
| 58 | } |
||
| 60 |