Passed
Pull Request — latest (#3)
by Mark
35:03
created

AbstractBlock   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 16
c 1
b 0
f 0
dl 0
loc 57
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getStartLine() 0 3 1
A getData() 0 5 2
A setParent() 0 7 3
A setEndLine() 0 3 1
A getEndLine() 0 3 1
A setStartLine() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file was originally part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
17
namespace UnicornFail\Emoji\Node\Block;
18
19
use UnicornFail\Emoji\Node\Node;
20
21
/**
22
 * Block-level element
23
 *
24
 * @method parent() ?AbstractBlock
25
 */
26
abstract class AbstractBlock extends Node
27
{
28
    /**
29
     * Used for storage of arbitrary data.
30
     *
31
     * @var array<string, mixed>
32
     */
33
    public $data = [];
34
35
    /** @var int|null */
36
    protected $startLine;
37
38
    /** @var int|null */
39
    protected $endLine;
40
41
    protected function setParent(?Node $node = null): void
42
    {
43
        if ($node && ! $node instanceof self) {
44
            throw new \InvalidArgumentException('Parent of block must also be block (cannot be inline)');
45
        }
46
47
        parent::setParent($node);
48
    }
49
50
    public function setStartLine(?int $startLine): void
51
    {
52
        $this->startLine = $startLine;
53
        if ($this->endLine === null) {
54
            $this->endLine = $startLine;
55
        }
56
    }
57
58
    public function getStartLine(): ?int
59
    {
60
        return $this->startLine;
61
    }
62
63
    public function setEndLine(?int $endLine): void
64
    {
65
        $this->endLine = $endLine;
66
    }
67
68
    public function getEndLine(): ?int
69
    {
70
        return $this->endLine;
71
    }
72
73
    /**
74
     * @param mixed $default
75
     *
76
     * @return mixed
77
     */
78
    public function getData(string $key, $default = null)
79
    {
80
        return \array_key_exists($key, $this->data)
81
            ? $this->data[$key]
82
            : $default;
83
    }
84
}
85