Test Failed
Pull Request — master (#97)
by Rafael
04:43 queued 43s
created

RouterProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 58
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attachRoutes() 0 6 2
A getMiddleware() 0 17 2
A getRoutes() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Providers;
6
7
use function Canvas\Core\appPath;
8
use Gewaer\Middleware\NotFoundMiddleware;
9
use Gewaer\Middleware\AuthenticationMiddleware;
10
use Gewaer\Middleware\TokenValidationMiddleware;
11
use Gewaer\Middleware\AclMiddleware;
12
use Canvas\Middleware\ThrottleMiddleware;
0 ignored issues
show
Bug introduced by
The type Canvas\Middleware\ThrottleMiddleware 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...
13
use Phalcon\Mvc\Micro;
14
use Canvas\Providers\RouterProvider as CanvasRouterProvider;
15
16
class RouterProvider extends CanvasRouterProvider
17
{
18
    /**
19
     * Attaches the routes to the application; lazy loaded.
20
     *
21
     * @param Micro $application
22 73
     */
23
    protected function attachRoutes(Micro $application)
24 73
    {
25
        $routes = $this->getRoutes();
26 73
27 73
        foreach ($routes as $route) {
28
            include $route;
29 73
        }
30
    }
31
32
    /**
33
     * Returns the array for the middleware with the action to attach.
34
     *
35
     * @return array
36 73
     */
37
    protected function getMiddleware(): array
38
    {
39 73
        if (!defined('API_TESTS')) {
40
            return [
41
                ThrottleMiddleware::class => 'before',
42
                TokenValidationMiddleware::class => 'before',
43
                NotFoundMiddleware::class => 'before',
44
                AuthenticationMiddleware::class => 'before',
45
                AclMiddleware::class => 'before',
46
            ];
47
        }
48
49
        return [
50
            TokenValidationMiddleware::class => 'before',
51 73
            NotFoundMiddleware::class => 'before',
52
            AuthenticationMiddleware::class => 'before',
53 73
            AclMiddleware::class => 'before',
54 73
        ];
55
        
56
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
57 73
58 73
    /**
59
     * Returns the array for all the routes on this system.
60
     *
61 73
     * @return array
62
     */
63
    protected function getRoutes(): array
64
    {
65
        $path = appPath('api/routes');
66
        $canvsaPath = getenv('CANVAS_CORE_PATH');
67
68
        $routes = [
69
            'api' => $path . '/api.php',
70
            'canvas' =>  $canvsaPath. '/routes/api.php'
71
        ];
72
73
        return $routes;
74
    }
75
}
76