| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class Heading extends BlockNode implements JsonSerializable |
||
| 18 | { |
||
| 19 | use TextBuilder; |
||
| 20 | use HeadingBuilder; |
||
| 21 | |||
| 22 | protected string $type = 'heading'; |
||
| 23 | protected array $allowedContentTypes = [ |
||
| 24 | InlineNode::class, |
||
| 25 | ]; |
||
| 26 | private int $level; |
||
| 27 | |||
| 28 | public function __construct(int $level, ?BlockNode $parent = null) |
||
| 32 | } |
||
| 33 | |||
| 34 | public static function load(array $data, ?BlockNode $parent = null): self |
||
| 35 | { |
||
| 36 | self::checkNodeData(static::class, $data, ['attrs']); |
||
| 37 | self::checkRequiredKeys(['level'], $data['attrs']); |
||
| 38 | |||
| 39 | $node = new self($data['attrs']['level'], $parent); |
||
| 40 | |||
| 41 | // set content if defined |
||
| 42 | if (\array_key_exists('content', $data)) { |
||
| 43 | foreach ($data['content'] as $nodeData) { |
||
| 44 | $class = Node::NODE_MAPPING[$nodeData['type']]; |
||
| 45 | $child = $class::load($nodeData, $node); |
||
| 46 | |||
| 47 | $node->append($child); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | return $node; |
||
| 52 | } |
||
| 53 | |||
| 54 | protected function attrs(): array |
||
| 60 | } |
||
| 61 | } |
||
| 62 |