Completed
Push — master ( a61ca1...848531 )
by Saurabh
01:36
created

RequestIdController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 44%

Importance

Changes 0
Metric Value
dl 0
loc 67
ccs 11
cts 25
cp 0.44
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A show() 0 6 1
B store() 0 30 2
1
<?php
2
3
namespace Sausin\Signere\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Sausin\Signere\RequestId;
7
use Illuminate\Support\Facades\Config;
8
9
class RequestIdController extends Controller
10
{
11
    /** @var \Sausin\Signere\RequestId */
12
    protected $signereRequest;
13
14
    /**
15
     * Create a new controller instance.
16
     *
17
     * @param  \Sausin\Signere\RequestId $signereRequest
18
     */
19 2
    public function __construct(RequestId $signereRequest)
20
    {
21 2
        parent::__construct();
22
23 2
        $this->signereRequest = $signereRequest;
24 2
    }
25
26
    /**
27
     * Check if a SignereID session is completed or not.
28
     *
29
     * @param  string $requestId
30
     * @return \Illuminate\Http\Response
31
     */
32 1
    public function show(string $requestId)
33
    {
34 1
        return $this->signereRequest->check($requestId)
35 1
                ->getBody()
36 1
                ->getContents();
37
    }
38
39
    /**
40
     * Creates a SignereID request, and returns a url.
41
     *
42
     * @param  Request $request
43
     * @return \Illuminate\Http\Response
44
     */
45 1
    public function store(Request $request)
46
    {
47 1
        $this->validate($request, [
48 1
            'session_id' => 'required|string',
49
            'person_number' => 'required|boolean',
50
            'language' => 'required|string|size:2|in:EN,NO,SV,DA,FI',
51
            'page_title' => 'sometimes|string',
52
            'iframe' => 'required|string|in:true,false',
53
            'iframe_height' => 'sometimes|nullable|numeric',
54
            'web_messaging' => 'required|string|in:true,false'
55
        ]);
56
57
        $body = [
58
            'CancelUrl' => Config::get('signere.cancel_url'),
59
            'Domain' => Config::get('signere.domain'),
60
            'ErrorUrl' => Config::get('signere.error_url'),
61
            'Height' => $request->iframe_height ?: Config::get('signere.iframe_height'),
62
            'SuccessUrl' => Config::get('signere.success_url'),
63
            'ExternalReference' => $request->session_id,
0 ignored issues
show
Bug introduced by
The property session_id does not seem to exist. Did you mean session?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64
            'IdentityProvider' => Config::get('signere.identity_provider'),
65
            'Language' => $request->language,
0 ignored issues
show
Bug introduced by
The property language does not seem to exist. Did you mean languages?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
66
            'PageTitle' => $request->page_title,
67
            'UseIframe' => $request->iframe,
68
            'UseWebMessaging' => $request->web_messaging
69
        ];
70
71
        return $this->signereRequest->create($body)
72
                ->getBody()
73
                ->getContents();
74
    }
75
}
76