| Conditions | 4 |
| Paths | 1 |
| Total Lines | 32 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 4.1106 |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | 3 | public function register() |
|
| 13 | { |
||
| 14 | /** |
||
| 15 | * Present controller method as `post` route. |
||
| 16 | */ |
||
| 17 | 3 | app('router')->macro('expose', |
|
| 18 | function ($controller = '', Array $actions) { |
||
| 19 | foreach ($actions as $action) { |
||
| 20 | $this->post(snake_case($action, '-'), |
||
| 21 | $controller.'@'.$action); |
||
| 22 | } |
||
| 23 | 3 | }); |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Expose all public methods of controller. |
||
| 27 | * @see `expose` macro /\ |
||
| 28 | */ |
||
| 29 | 3 | app('router')->macro('exposeAll', function ($controllerClassName) { |
|
| 30 | 3 | $controllerClassReflection = new \ReflectionClass($controllerClassName); |
|
| 31 | 3 | $publicActions = $controllerClassReflection->getMethods(\ReflectionMethod::IS_PUBLIC); |
|
| 32 | 3 | foreach ($publicActions as $publicAction) { |
|
| 33 | 3 | $declaringClass = $publicAction->getDeclaringClass()->getName(); |
|
| 34 | 3 | $isOwn = $declaringClass === $controllerClassName; |
|
| 35 | 3 | if (! $isOwn) { |
|
| 36 | 3 | continue; |
|
| 37 | } |
||
| 38 | 3 | $action = $publicAction->getName(); |
|
| 39 | 3 | $this->post(snake_case($action, '-'), |
|
| 40 | 3 | $controllerClassName.'@'.$action); |
|
| 41 | 2 | } |
|
| 42 | 3 | }); |
|
| 43 | } |
||
| 44 | } |