1 | <?php declare(strict_types=1); |
||
13 | abstract class AbstractCharacterGroup |
||
14 | { |
||
15 | /** string Character group matching regexp pattern matching group name */ |
||
16 | const PATTERN_GROUP = ''; |
||
17 | |||
18 | /** string Regular expression matching character group */ |
||
19 | const PATTERN_REGEXP = ''; |
||
20 | |||
21 | /** string Character group matching regexp pattern */ |
||
22 | const PATTERN = ''; |
||
23 | |||
24 | /** @var int Character group length */ |
||
25 | public $length; |
||
26 | |||
27 | /** @var string Character group string */ |
||
28 | public $string; |
||
29 | |||
30 | /** @var int Character group size */ |
||
31 | protected $size = 1; |
||
32 | |||
33 | /** |
||
34 | * AbstractCharacterGroup constructor. |
||
35 | * |
||
36 | * @param string $string Character group string |
||
37 | * @param int $length Character group length |
||
38 | */ |
||
39 | 18 | public function __construct(string $string, int $length = 0) |
|
44 | |||
45 | /** |
||
46 | * Create character group from input string. |
||
47 | * |
||
48 | * @param string $input Input string |
||
49 | * |
||
50 | * @return null|AbstractCharacterGroup|FixedCG|VariableCG|FixedVariableFixedCG Character group instance |
||
51 | */ |
||
52 | 14 | public static function fromString(string &$input) |
|
64 | |||
65 | /** |
||
66 | * @return bool True if character group is variable length otherwise false |
||
67 | */ |
||
68 | 1 | public function isVariable(): bool |
|
72 | |||
73 | /** |
||
74 | * Compare character groups. |
||
75 | * |
||
76 | * @param AbstractCharacterGroup $group Compared character group |
||
77 | * |
||
78 | * @return int -1, 0, 1 Lower, equal, higher |
||
79 | */ |
||
80 | 14 | public function compare(AbstractCharacterGroup $group): int |
|
95 | |||
96 | /** |
||
97 | * Check if compared character group has same type. |
||
98 | * |
||
99 | * @param AbstractCharacterGroup $group Compared character group |
||
100 | * |
||
101 | * @return bool True if character group has same type otherwise false |
||
102 | */ |
||
103 | 15 | public function isSameType(AbstractCharacterGroup $group): bool |
|
107 | |||
108 | /** |
||
109 | * Compare this character group length to compared character group length. |
||
110 | * |
||
111 | * @param AbstractCharacterGroup $group Compared character group |
||
112 | * |
||
113 | * @return int -1, 0, 1 Character groups comparison result |
||
114 | */ |
||
115 | abstract protected function compareLength(AbstractCharacterGroup $group): int; |
||
116 | |||
117 | /** |
||
118 | * @return bool True if character group is fixed length otherwise false |
||
119 | */ |
||
120 | 6 | public function isFixed(): bool |
|
124 | } |
||
125 |