| Total Complexity | 9 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 90.91% |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | class PresenterNormalizer implements NormalizerContract |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Figures out which method should be called as the presenter. |
||
| 11 | * |
||
| 12 | * @param object $widget |
||
| 13 | * @return void |
||
| 14 | */ |
||
| 15 | 24 | public function normalize($widget): void |
|
| 16 | { |
||
| 17 | 24 | $presenter = $this->figureOutPresenterClass($widget); |
|
| 18 | |||
| 19 | 24 | if ($widget->presenter) { |
|
| 20 | 1 | $this->checkPresentMethodExists($presenter); |
|
| 21 | 1 | $widget->presenter = $presenter.'@present'; |
|
|
|
|||
| 22 | } |
||
| 23 | 24 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $presenter |
||
| 27 | */ |
||
| 28 | 1 | private function checkPresentMethodExists($presenter): void |
|
| 29 | { |
||
| 30 | 1 | if (! method_exists($presenter, 'present')) { |
|
| 31 | throw new \InvalidArgumentException("'present' method not found on : ".$presenter); |
||
| 32 | } |
||
| 33 | 1 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $presenter |
||
| 37 | */ |
||
| 38 | 1 | private function checkPresenterExists($presenter): void |
|
| 39 | { |
||
| 40 | 1 | if (! class_exists($presenter)) { |
|
| 41 | throw new \InvalidArgumentException("Presenter Class [{$presenter}] not found."); |
||
| 42 | } |
||
| 43 | 1 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @param $widget |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | 24 | private function figureOutPresenterClass($widget): string |
|
| 62 | } |
||
| 63 | } |
||
| 64 |