File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Permafrost \CodeSnippets ;
4
+
5
+ class Bounds
6
+ {
7
+ /** @var int */
8
+ public $ start = 0 ;
9
+
10
+ /** @var int */
11
+ public $ end = 0 ;
12
+
13
+ public function __construct (int $ start , int $ end )
14
+ {
15
+ $ this ->start = $ start ;
16
+ $ this ->end = $ end ;
17
+ }
18
+
19
+ public static function create (int $ start , int $ end ): self
20
+ {
21
+ return new static (...func_get_args ());
22
+ }
23
+
24
+ public static function createFromArray (array $ lineNumbers ): self
25
+ {
26
+ sort ($ lineNumbers , SORT_NUMERIC );
27
+
28
+ return static ::create ($ lineNumbers [0 ], $ lineNumbers [count ($ lineNumbers ) - 1 ]);
29
+ }
30
+
31
+ public function toArray (): array
32
+ {
33
+ return [$ this ->start , $ this ->end ];
34
+ }
35
+
36
+ public function mergeWith (self $ bounds ): self
37
+ {
38
+ $ data = array_merge ($ this ->toArray (), $ bounds ->toArray ());
39
+
40
+ return static ::createFromArray ($ data );
41
+ }
42
+
43
+ public function copy (self $ bounds ): self
44
+ {
45
+ $ this ->start = $ bounds ->start ;
46
+ $ this ->end = $ bounds ->end ;
47
+
48
+ return $ this ;
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments