| Total Complexity | 8 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | abstract class CanonicalRange extends Range |
||
| 11 | { |
||
| 12 | public function __construct(?string $from = null, ?string $to = null, string $fromBound = '[', string $toBound = ')') |
||
| 13 | { |
||
| 14 | parent::__construct($from, $to, $fromBound, $toBound); |
||
| 15 | $this->canonicalizeBoundaries(); |
||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The built-in range types int4range, int8range, and daterange all use a canonical form |
||
| 20 | * that includes the lower bound and excludes the upper bound; that is, [). |
||
| 21 | */ |
||
| 22 | private function canonicalizeBoundaries(): void |
||
| 23 | { |
||
| 24 | $this->canonicalizeLowerBoundary(); |
||
| 25 | $this->canonicalizeUpperBoundary(); |
||
| 26 | } |
||
| 27 | |||
| 28 | private function canonicalizeLowerBoundary(): void |
||
| 29 | { |
||
| 30 | if ($this->fromBound === '(') { |
||
| 31 | if ($this->from !== null) { |
||
| 32 | $this->from = $this->addToDiscreteBoundary($this->from); |
||
| 33 | } |
||
| 34 | $this->fromBound = '['; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $boundary |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | abstract protected function addToDiscreteBoundary(string $boundary): string; |
||
| 43 | |||
| 44 | private function canonicalizeUpperBoundary(): void |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 |