ShariffController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 5
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAction() 0 18 4
1
<?php
2
3
namespace CedricZiel\ShariffBundle\Controller;
4
5
use CedricZiel\ShariffBundle\Model\ShariffConfig;
6
use CedricZiel\ShariffBundle\Service\ShariffServiceInterface;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
10
/**
11
 * @package CedricZiel\ShariffBundle\Controller
12
 */
13
class ShariffController
14
{
15
    /**
16
     * @var  ShariffServiceInterface
17
     */
18
    protected $shariffService;
19
20
    /**
21
     * @var ShariffConfig
22
     */
23
    protected $config;
24
25
    /**
26
     * ShariffController constructor.
27
     *
28
     * @param ShariffServiceInterface $shariffService
29
     * @param ShariffConfig           $config
30
     */
31
    public function __construct(ShariffServiceInterface $shariffService, ShariffConfig $config)
32
    {
33
        $this->shariffService = $shariffService;
34
        $this->config = $config;
35
    }
36
37
    /**
38
     * @param Request $request
39
     *
40
     * @return \Symfony\Component\HttpFoundation\Response
41
     */
42
    public function getAction(Request $request)
43
    {
44
        $url = $request->query->get('url');
45
        $forceProtocol = $this->config->getForceProtocol();
46
47
        if (!is_null($forceProtocol)) {
48
            if ($forceProtocol === "https") {
49
                $url = str_replace('http://', 'https://', $url);
50
            }
51
            if ($forceProtocol === "http") {
52
                $url = str_replace('https://', 'http://', $url);
53
            }
54
        }
55
56
        $result = $this->shariffService->get($url);
57
58
        return new JsonResponse($result);
59
    }
60
}
61