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

RequestIdController::store()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.2337

Importance

Changes 0
Metric Value
cc 2
eloc 24
nc 2
nop 1
dl 0
loc 30
ccs 3
cts 17
cp 0.1765
crap 4.2337
rs 8.8571
c 0
b 0
f 0
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