Passed
Push — master ( 412379...918393 )
by Mike
03:18
created

RouteProvider::createRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace App\Application\Routing;
5
6
7
use Laravel\Lumen\Routing\Router;
8
use App\Application\Controller\StatusController;
0 ignored issues
show
Bug introduced by
The type App\Application\Controller\StatusController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use App\User\Controller\SkeletonController;
10
use App\User\Controller\UserController;
11
use Xervice\Service\Route\RouteInterface;
12
13
class RouteProvider implements RouteInterface
14
{
15
    public function register(Router $router)
16
    {
17
        $routings = [
18
            'post' => [
19
                [
20
                    '/api/user/{method}',
21
                    UserController::class,
22
                    'apiAction'
23
                ]
24
            ]
25
        ];
26
27
        $this->handleRoutings($router, $routings, 'get');
28
        $this->handleRoutings($router, $routings, 'post');
29
        $this->handleRoutings($router, $routings, 'delete');
30
        $this->handleRoutings($router, $routings, 'put');
31
32
        $this->skeletonRoutings($router);
33
    }
34
35
    /**
36
     * @param \Laravel\Lumen\Routing\Router $router
37
     */
38
    private function skeletonRoutings(Router $router): void
39
    {
40
        $router->get('/api/user/register/skeleton', SkeletonController::class . '@registerSekeleton');
41
    }
42
43
    /**
44
     * @param \Laravel\Lumen\Routing\Router $router
45
     * @param array $routings
46
     * @param string $type
47
     */
48
    private function handleRoutings(Router $router, array $routings, string $type): void
49
    {
50
        $routings[$type] = $routings[$type] ?? [];
51
        foreach ($routings[$type] as $route) {
52
            $this->createRoute($router, $route, $type);
53
        }
54
    }
55
56
    /**
57
     * @param \Laravel\Lumen\Routing\Router $router
58
     * @param $route
59
     */
60
    private function createRoute(Router $router, array $route, string $type): void
61
    {
62
        $router->$type($route[0], $route[1] . '@' . $route[2]);
63
    }
64
65
}