Completed
Push — 0.3.x ( 921e84...1e8c09 )
by Dmitry
14:16
created

HttpUtils   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 2
cbo 3
dl 0
loc 87
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createRedirectResponse() 0 4 1
A createSignedRedirectResponse() 0 4 1
A createWrappedTargetPath() 0 4 1
A hasTargetPath() 0 4 1
A checkUrl() 0 4 1
A __construct() 0 8 1
1
<?php
2
3
namespace Krtv\Bundle\SingleSignOnIdentityProviderBundle\Security\Http;
4
5
use Symfony\Component\HttpFoundation\RedirectResponse;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpKernel\UriSigner;
8
use Symfony\Component\Security\Http;
9
10
/**
11
 * Class HttpUtils
12
 * @package Krtv\Bundle\SingleSignOnIdentityProviderBundle\Security\Http
13
 */
14
class HttpUtils
15
{
16
    /**
17
     * @var UriSigner
18
     */
19
    private $uriSigner;
20
21
    /**
22
     * @var Http\HttpUtils
23
     */
24
    private $httpUtils;
25
26
    /**
27
     * @var string
28
     */
29
    private $otpParameter;
30
31
    /**
32
     * @var string
33
     */
34
    private $targetPathParameter;
35
36
    /**
37
     * @param UriSigner      $uriSigner
38
     * @param Http\HttpUtils $httpUtils
39
     * @param string         $otpParameter
40
     * @param string         $targetPathParameter
41
     */
42 6
    public function __construct(UriSigner $uriSigner, Http\HttpUtils $httpUtils, $otpParameter, $targetPathParameter)
43
    {
44 6
        $this->uriSigner = $uriSigner;
45 6
        $this->httpUtils = $httpUtils;
46
47 6
        $this->otpParameter = $otpParameter;
48 6
        $this->targetPathParameter = $targetPathParameter;
49 6
    }
50
51
    /**
52
     * @param Request $request
53
     * @param string  $path
54
     * @param int     $status
55
     * @return RedirectResponse
56
     */
57 5
    public function createRedirectResponse(Request $request, $path, $status = 302)
58
    {
59 5
        return $this->httpUtils->createRedirectResponse($request, $path, $status);
60
    }
61
62
    /**
63
     * @param Request $request
64
     * @param string  $path
65
     * @param int     $status
66
     * @return RedirectResponse
67
     */
68 2
    public function createSignedRedirectResponse(Request $request, $path, $status = 302)
69
    {
70 2
        return $this->httpUtils->createRedirectResponse($request, $this->uriSigner->sign($path), $status);
71
    }
72
73
    /**
74
     * @param Request $request
75
     * @param string  $otp
76
     * @return string
77
     */
78 2
    public function createWrappedTargetPath(Request $request, $otp)
79
    {
80 2
        return sprintf('%s&%s=%s', $request->get($this->targetPathParameter), $this->otpParameter, rawurlencode($otp));
81
    }
82
83
    /**
84
     * @param Request $request
85
     * @return bool
86
     */
87 6
    public function hasTargetPath(Request $request)
88
    {
89 6
        return $request->get($this->targetPathParameter) != '';
90
    }
91
92
    /**
93
     * @param string $uri
94
     * @return bool
95
     */
96 5
    public function checkUrl($uri)
97
    {
98 5
        return $this->uriSigner->check($uri);
99
    }
100
}
101