| Total Complexity | 5 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class CustomPropertiesRenderer implements Renderer |
||
| 11 | { |
||
| 12 | private array $exclude; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param array<int, int> $exclude Values list that should be excluded |
||
| 16 | */ |
||
| 17 | public function __construct(array $exclude) |
||
| 18 | { |
||
| 19 | $this->exclude = $exclude; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function render(Formatter $formatter, array $schema, string $role): ?string |
||
| 23 | { |
||
| 24 | $customProperties = \array_diff(\array_keys($schema), $this->exclude); |
||
| 25 | |||
| 26 | if ($customProperties === []) { |
||
| 27 | return null; |
||
| 28 | } |
||
| 29 | |||
| 30 | $rows = [ |
||
| 31 | \sprintf('%s:', $formatter->title('Custom props')), |
||
| 32 | ]; |
||
| 33 | |||
| 34 | foreach ($customProperties as $property) { |
||
| 35 | $data = $schema[$property] ?? null; |
||
| 36 | |||
| 37 | $rows[] = \sprintf( |
||
| 38 | '%s%s: %s', |
||
| 39 | $formatter->title(' '), |
||
| 40 | $property, |
||
| 41 | $formatter->typecast($this->printValue($data, $formatter)) |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | return \implode($formatter::LINE_SEPARATOR, $rows); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param mixed $value |
||
| 50 | */ |
||
| 51 | private function printValue($value, Formatter $formatter): string |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |