DocumentJobController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 82
ccs 19
cts 19
cp 1
rs 10
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() 0 43 2
1
<?php
2
3
namespace Sausin\Signere\Http\Controllers\Admin;
4
5
use Illuminate\Http\Request;
6
use Sausin\Signere\DocumentJob;
7
use Sausin\Signere\Http\Controllers\Controller;
8
9
class DocumentJobController extends Controller
10
{
11
    /** @var \Sausin\Signere\DocumentJob */
12
    protected $dj;
13
14
    /**
15
     * Create a new controller instance.
16
     *
17
     * @param  \Sausin\Signere\DocumentJob $dj
18
     */
19 3
    public function __construct(DocumentJob $dj)
20
    {
21 3
        parent::__construct();
22
23 3
        $this->dj = $dj;
24 3
    }
25
26
    /**
27
     * Retrieves a document job in the form of a response
28
     * object containing the document job parameters.
29
     *
30
     * @param  string $jobId
31
     * @return \Illuminate\Http\Response
32
     */
33 1
    public function show(string $jobId)
34
    {
35 1
        return $this->dj->get($jobId)
36 1
                ->getBody()
37 1
                ->getContents();
38
    }
39
40
    /**
41
     * Retrieves a document job in the form of a response
42
     * object containing the document job parameters.
43
     *
44
     * @param  Request $request
45
     * @return \Illuminate\Http\Response
46
     */
47 2
    public function store(Request $request)
48
    {
49 2
        $this->validate($request, [
50 2
            'email' => 'bail|required|email|max:255',
51
            'mobile' => [
52
                'bail',
53
                'nullable',
54
                'string',
55
                'regex:/^\+47\d{8}$/i',
56
            ],
57
            'name' => 'bail|nullable|string|min:1|max:255',
58
            'phone' => [
59
                'bail',
60
                'required',
61
                'string',
62
                'regex:/^\+47\d{8}$/i',
63
            ],
64
            'url' => 'bail|nullable|url',
65
        ]);
66
67
        // this is used to only set the keys which have been sent in
68
        $useKeys = [
69 2
            'email' => 'Contact_Email',
70
            'mobile' => 'Contact_Mobile',
71
            'name' => 'Contact_Name',
72
            'phone' => 'Contact_Phone',
73
            'url' => 'Contact_Url',
74
        ];
75
76
        // check which keys are available in the request
77 2
        $available = array_intersect(array_keys($useKeys), array_keys($request->all()));
78
79 2
        $body = [];
80
81
        // set the body up
82 2
        foreach ($available as $use) {
83 2
            $body[$useKeys[$use]] = $request->$use;
84
        }
85
86 2
        return $this->dj->create($body)
87 2
                ->getBody()
88 2
                ->getContents();
89
    }
90
}
91