Passed
Push — master ( c5bd37...640ffc )
by
unknown
05:22
created

ApieRouteLoader::renderContext()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 22
nc 6
nop 1
dl 0
loc 32
rs 9.568
c 1
b 0
f 0
1
<?php
2
3
4
namespace W2w\Laravel\Apie\Services;
5
6
class ApieRouteLoader
7
{
8
    private $context;
9
10
    private $routeLoader;
11
12
    public function __construct(ApieContext $context, RouteLoaderInterface $routeLoader) {
13
        $this->context = $context;
14
        $this->routeLoader = $routeLoader;
15
    }
16
17
    public function renderRoutes()
18
    {
19
        $this->renderContext($this->context);
20
    }
21
22
    private function renderContext(ApieContext $context)
23
    {
24
        if (!$context->getConfig('disable-routes')) {
25
            $this->routeLoader->context(
26
                $context->getContextKey(),
27
                $context->getConfig('api-url'),
28
                $context->getConfig('swagger-ui-test-page-middleware'),
29
                function () use ($context) {
30
                    $this->routeLoader->addDocUrl($context->getContextKey());
31
                }
32
            );
33
            $this->routeLoader->context(
34
                $context->getContextKey(),
35
                $context->getConfig('api-url'),
36
                $context->getConfig('apie-middleware'),
37
                function () use ($context) {
38
                    $this->routeLoader->addResourceUrl($context->getContextKey());
39
                }
40
            );
41
            if ($context->getConfig('swagger-ui-test-page')) {
42
                $this->routeLoader->context(
43
                    $context->getContextKey(),
44
                    $context->getConfig('swagger-ui-test-page'),
45
                    $context->getConfig('swagger-ui-test-page-middleware'),
46
                    function () use ($context) {
47
                        $this->routeLoader->addSwaggerUiUrl($context->getContextKey());
48
                    }
49
                );
50
            }
51
        }
52
        foreach ($context->allContexts() as $childContext) {
53
            $this->renderContext($childContext);
54
        }
55
    }
56
}
57