SwaggerService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 59
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSwaggerResponse() 0 15 1
A getSwagger() 0 9 1
1
<?php
2
3
namespace Basster\Silex\Provider\Swagger;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * Class SwaggerService
11
 *
12
 * @package Basster\Silex\Provider\Swagger
13
 */
14
class SwaggerService
15
{
16
    /**
17
     * @var SwaggerConfig
18
     */
19
    private $config;
20
21
    /**
22
     * @var array
23
     */
24
    private $cacheConfig;
25
26
    /**
27
     * SwaggerService constructor.
28
     *
29
     * @param SwaggerConfig $config
30
     * @param array         $cacheConfig
31
     */
32 4
    public function __construct(SwaggerConfig $config, array $cacheConfig = [])
33
    {
34 4
        $this->config      = $config;
35 4
        $this->cacheConfig = $cacheConfig;
36 4
    }
37
38
    /**
39
     * @param \Symfony\Component\HttpFoundation\Request $request
40
     *
41
     * @return \Symfony\Component\HttpFoundation\Response
42
     * @throws \InvalidArgumentException
43
     */
44 1
    public function getSwaggerResponse(Request $request)
45
    {
46 1
        $swagger = $this->getSwagger();
47
48 1
        $response = Response::create(
49 1
          $swagger,
50 1
          Response::HTTP_OK,
51 1
          ['Content-Type' => 'application/json']
52 1
        );
53 1
        $response->setCache($this->cacheConfig);
54 1
        $response->setEtag(md5($swagger));
55 1
        $response->isNotModified($request);
56
57 1
        return $response;
58
    }
59
60
    /**
61
     * @return \Swagger\Annotations\Swagger
62
     */
63 1
    public function getSwagger()
64
    {
65 1
        $swagger = \Swagger\scan(
66 1
          $this->config->getBasePath(),
67 1
          $this->config->getScanOptions()
68 1
        );
69
70 1
        return $swagger;
71
    }
72
}
73