Completed
Push — master ( 5b1884...46f07a )
by Ole
04:10
created

SwaggerService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 49
rs 10

3 Methods

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