1 | <?php |
||
2 | |||
3 | namespace Spatie\CodeOutline\Elements; |
||
4 | |||
5 | use Spatie\Typed\Collection; |
||
6 | use Spatie\Typed\T; |
||
7 | |||
8 | class Line extends Collection |
||
9 | { |
||
10 | public function __construct(int ...$values) |
||
11 | { |
||
12 | parent::__construct(T::int()); |
||
13 | |||
14 | $this->set($values); |
||
15 | } |
||
16 | |||
17 | public static function make(int $indentationCount, int $characterCount): self |
||
18 | { |
||
19 | $indentationValues = array_fill(0, $indentationCount, -1); |
||
20 | |||
21 | $characterValues = array_fill(0, $characterCount, 1); |
||
22 | |||
23 | $lineValues = array_merge($indentationValues, $characterValues); |
||
24 | |||
25 | return new self(...$lineValues); |
||
26 | } |
||
27 | |||
28 | public function merge(self $line): self |
||
29 | { |
||
30 | $mergedLine = clone $this; |
||
31 | |||
32 | foreach ($line as $position => $value) { |
||
33 | $mergedLine[$position] = ($this[$position] ?? 0) + $value; |
||
34 | } |
||
35 | |||
36 | return $mergedLine; |
||
37 | } |
||
38 | |||
39 | public function getMaximumCharacterPositionDensity(): int |
||
40 | { |
||
41 | return $this->count() |
||
42 | ? max($this->data) |
||
43 | : 0; |
||
44 | } |
||
45 | |||
46 | public function offsetGet($offset): int |
||
47 | { |
||
48 | return parent::offsetGet($offset); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
49 | } |
||
50 | } |
||
51 |