PageBlockDetails::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This phpFile is auto-generated.
5
 */
6
7
declare(strict_types=1);
8
9
namespace PHPTdGram\Schema;
10
11
/**
12
 * A collapsible block.
13
 */
14
class PageBlockDetails extends PageBlock
15
{
16
    public const TYPE_NAME = 'pageBlockDetails';
17
18
    /**
19
     * Always visible heading for the block.
20
     */
21
    protected RichText $header;
22
23
    /**
24
     * Block contents.
25
     *
26
     * @var PageBlock[]
27
     */
28
    protected array $pageBlocks;
29
30
    /**
31
     * True, if the block is open by default.
32
     */
33
    protected bool $isOpen;
34
35
    public function __construct(RichText $header, array $pageBlocks, bool $isOpen)
36
    {
37
        parent::__construct();
38
39
        $this->header     = $header;
40
        $this->pageBlocks = $pageBlocks;
41
        $this->isOpen     = $isOpen;
42
    }
43
44
    public static function fromArray(array $array): PageBlockDetails
45
    {
46
        return new static(
47
            TdSchemaRegistry::fromArray($array['header']),
48
            array_map(fn ($x) => TdSchemaRegistry::fromArray($x), $array['pageBlocks']),
49
            $array['is_open'],
50
        );
51
    }
52
53
    public function typeSerialize(): array
54
    {
55
        return [
56
            '@type'           => static::TYPE_NAME,
57
            'header'          => $this->header->typeSerialize(),
58
            array_map(fn ($x) => $x->typeSerialize(), $this->pageBlocks),
59
            'is_open'         => $this->isOpen,
60
        ];
61
    }
62
63
    public function getHeader(): RichText
64
    {
65
        return $this->header;
66
    }
67
68
    public function getPageBlocks(): array
69
    {
70
        return $this->pageBlocks;
71
    }
72
73
    public function getIsOpen(): bool
74
    {
75
        return $this->isOpen;
76
    }
77
}
78