MobileExternalSignController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 51.32 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 39
loc 76
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A show() 0 6 1
B store() 39 39 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Sausin\Signere\Http\Controllers\Admin;
4
5
use Illuminate\Http\Request;
6
use Sausin\Signere\ExternalSign;
7
use Sausin\Signere\Http\Controllers\Controller;
8
9
class MobileExternalSignController extends Controller
10
{
11
    /** @var \Sausin\Signere\ExternalSign */
12
    protected $extSign;
13
14
    /**
15
     * Create a new controller instance.
16
     *
17
     * @param  \Sausin\Signere\ExternalSign $extSign
18
     */
19
    public function __construct(ExternalSign $extSign)
20
    {
21
        parent::__construct();
22
23
        $this->extSign = $extSign;
24
    }
25
26
    /**
27
     * Get status of the BankID mobile Sign session.
28
     *
29
     * @param  string $signeeRefId
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function show(string $signeeRefId)
33
    {
34
        return $this->extSign->getSessionStatus($signeeRefId)
35
                ->getBody()
36
                ->getContents();
37
    }
38
39
    /**
40
     * Starts a BankID mobile sign session for the given document.
41
     *
42
     * @param  Request $request
43
     * @return \Illuminate\Http\Response
44
     */
45 View Code Duplication
    public function store(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $this->validate($request, [
48
            'birth_date' => [
49
                'required',
50
                'string',
51
                'size:6',
52
                'regex:/^\d{6}$/i',
53
            ],
54
            'document_id' => 'required|string|size:36',
55
            'phone_number' => [
56
                'required',
57
                'regex:/^\+47\d{8}$/i',
58
            ],
59
            'signee_ref' => 'required|string|size:36',
60
        ]);
61
62
        // this is used to only set the keys which have been sent in
63
        $useKeys = [
64
            'birth_date' => 'DateOfBirth',
65
            'document_id' => 'DocumentID',
66
            'phone_number' => 'Mobile',
67
            'signee_ref' => 'SigneeRef',
68
        ];
69
70
        // check which keys are available in the request
71
        $available = array_intersect(array_keys($useKeys), array_keys($request->all()));
72
73
        $body = [];
74
75
        // set the body up
76
        foreach ($available as $use) {
77
            $body[$useKeys[$use]] = $request->$use;
78
        }
79
80
        return $this->extSign->startMobile($body)
81
                ->getBody()
82
                ->getContents();
83
    }
84
}
85