Completed
Push — master ( 330252...19e909 )
by Michael
04:10 queued 02:11
created

VigLinkController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B keyAction() 0 38 4
A enabledAction() 0 7 1
1
<?php
2
3
namespace AppBundle\Controller;
4
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Component\HttpFoundation\Request;
7
8
class VigLinkController extends Controller
9
{
10
	public function keyAction(Request $request)
11
	{
12
		$siteId = $request->query->get('siteid');
13
		$uuid = $request->query->get('uuid');
14
		$apiKey = $request->query->get('key');
15
		$siteDomain = $request->query->get('domain');
16
17
		if (!isset($siteId, $uuid, $apiKey, $siteDomain))
18
		{
19
			throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
20
		}
21
22
		$subId = md5($siteId . $uuid);
23
		$expiration = strtotime("+1 year");
24
		$key = $this->container->hasParameter('viglink_api_key') ? $this->getParameter('viglink_api_key') : $apiKey;
25
26
		if (!$this->container->hasParameter('viglink_secret_key')) {
27
			throw new \Exception('Viglink is not enabled');
28
		}
29
30
		$secretKey = $this->getParameter('viglink_secret_key');
31
32
		$url = ("https://www.viglink.com/users/convertAccount?key=" . $key . "&subId=" . $subId);
33
		$signature = hash_hmac('md5', ($url . "-" . $expiration), $secretKey);
34
35
		$queryParams = http_build_query(
36
			['key' => $key,
37
			'subId' => $subId,
38
			'expiration' => $expiration,
39
			'signature' => $signature,]
40
		);
41
42
		$url = ('https://www.viglink.com/users/convertAccount?' . $queryParams);
43
44
		$response = new Response($url);
45
46
		return $response;
47
	}
48
49
	public function enabledAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
	{
51
		$response = new Response('1');
52
		// Set to '0' to disable viglink
53
54
		return $response;
55
	}
56
}
57