| Total Complexity | 5 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | final class FrameRevolverBuilder implements IFrameRevolverBuilder |
||
| 18 | { |
||
| 19 | private ?IFrameCollection $frames = null; |
||
| 20 | private ?IInterval $interval = null; |
||
| 21 | private ?ITolerance $tolerance = null; |
||
| 22 | |||
| 23 | public function build(): IFrameRevolver |
||
| 24 | { |
||
| 25 | $this->validate(); |
||
| 26 | |||
| 27 | return new FrameCollectionRevolver( |
||
| 28 | $this->frames, |
||
|
|
|||
| 29 | $this->interval, |
||
| 30 | $this->tolerance, |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | private function validate(): void |
||
| 35 | { |
||
| 36 | match (true) { |
||
| 37 | $this->frames === null => throw new LogicException('Frame collection is not set.'), |
||
| 38 | $this->interval === null => throw new LogicException('Interval is not set.'), |
||
| 39 | $this->tolerance === null => throw new LogicException('Tolerance is not set.'), |
||
| 40 | default => null, |
||
| 41 | }; |
||
| 42 | } |
||
| 43 | |||
| 44 | public function withFrameCollection(IFrameCollection $frames): IFrameRevolverBuilder |
||
| 45 | { |
||
| 46 | $clone = clone $this; |
||
| 47 | $clone->frames = $frames; |
||
| 48 | return $clone; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function withInterval(IInterval $interval): IFrameRevolverBuilder |
||
| 52 | { |
||
| 53 | $clone = clone $this; |
||
| 54 | $clone->interval = $interval; |
||
| 55 | return $clone; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function withTolerance(ITolerance $tolerance): IFrameRevolverBuilder |
||
| 63 | } |
||
| 64 | } |
||
| 65 |