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