SwaggerUI   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 16 1
1
<?php
2
3
namespace SwaggerMiddleware\Middleware;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Server\RequestHandlerInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Zend\Diactoros\Response\HtmlResponse;
9
10
class SwaggerUI implements RequestHandlerInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $config;
16
17 6
    public function __construct(array $config)
18
    {
19 6
        $this->config = $config;
20 6
    }
21
22 3
    public function handle(ServerRequestInterface $request): ResponseInterface
23
    {
24 3
        $template = file_get_contents(dirname(__DIR__).'/templates/documentation.phtml');
25
26 3
        $template = str_replace([
27 3
            '{__TITLE__}',
28
            '{__ASSETS_PATH__}',
29
            '{__API_SPEC_URL__}',
30
        ], [
31 3
            $this->config['title'],
32 3
            $this->config['routes']['assets'],
33 3
            $this->config['routes']['specification'],
34 2
        ], $template);
35
36 3
        return new HtmlResponse($template);
37
    }
38
}
39