SwaggerUiController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 17
c 2
b 0
f 1
dl 0
loc 35
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 15 3
1
<?php
2
namespace W2w\Laravel\Apie\Controllers;
3
4
use Illuminate\Contracts\Routing\UrlGenerator as LaravelUrlGenerator;
5
use Laravel\Lumen\Routing\UrlGenerator as LumenUrlGenerator;
0 ignored issues
show
Bug introduced by
The type Laravel\Lumen\Routing\UrlGenerator 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...
6
use W2w\Laravel\Apie\Exceptions\FileNotFoundException;
7
use W2w\Laravel\Apie\Services\ApieContext;
8
use Zend\Diactoros\Response\TextResponse;
0 ignored issues
show
Bug introduced by
The type Zend\Diactoros\Response\TextResponse 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
10
/**
11
 * Renders swagger UI for the openAPI spec generated by Apie.
12
 */
13
class SwaggerUiController
14
{
15
    private $apieContext;
16
17
    private $urlGenerator;
18
19
    private $htmlLocation;
20
21
    /**
22
     * @param ApieContext                           $apieContext
23
     * @param LaravelUrlGenerator|LumenUrlGenerator $urlGenerator
24
     * @param string                                $htmlLocation
25
     */
26
    public function __construct(ApieContext $apieContext, $urlGenerator, string $htmlLocation)
27
    {
28
        $this->apieContext = $apieContext;
29
        $this->urlGenerator = $urlGenerator;
30
        $this->htmlLocation = $htmlLocation;
31
    }
32
33
    public function __invoke()
34
    {
35
        $contents = @file_get_contents($this->htmlLocation);
36
        if (false === $contents) {
37
            throw new FileNotFoundException($this->htmlLocation);
38
        }
39
        $context = $this->apieContext->getActiveContext()->getContextKey();
40
        $contextString = empty($context) ? '' : (implode('.', $context) . '.');
41
        $url = $this->urlGenerator->route('apie.' . $contextString . 'docsyaml');
42
43
        return new TextResponse(
44
            str_replace('{{ url }}', $url, $contents),
45
            200,
46
            [
47
                'content-type' => 'text/html'
48
            ]
49
        );
50
    }
51
}
52