ExternalSignController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sausin\Signere\Http\Controllers\Admin;
4
5
use Illuminate\Http\Request;
6
use Sausin\Signere\ExternalSign;
7
use Illuminate\Support\Facades\Config;
8
use Sausin\Signere\Http\Controllers\Controller;
9
10
class ExternalSignController extends Controller
11
{
12
    /** @var \Sausin\Signere\ExternalSign */
13
    protected $extSign;
14
15
    /**
16
     * Create a new controller instance.
17
     *
18
     * @param  \Sausin\Signere\ExternalSign $extSign
19
     */
20 3
    public function __construct(ExternalSign $extSign)
21
    {
22 3
        parent::__construct();
23
24 3
        $this->extSign = $extSign;
25 3
    }
26
27
    /**
28
     * Get the URLs to sign the Document.
29
     *
30
     * @param  string $documentId
31
     * @return \Illuminate\Http\Response
32
     */
33 1
    public function index(string $documentId)
34
    {
35 1
        return $this->extSign->getUrlForSign($documentId)
36 1
                ->getBody()
37 1
                ->getContents();
38
    }
39
40
    /**
41
     * Get the URLs to view a viewerapplet in a iFrame on your site.
42
     *
43
     * @param  string $documentId
44
     * @param  string $domain
45
     * @param  string $language
46
     * @return \Illuminate\Http\Response
47
     */
48 1
    public function show(string $documentId, string $domain, string $language)
49
    {
50 1
        return $this->extSign->getUrlForApplet($documentId, ['Domain' => $domain, 'Language' => $language])
51 1
                ->getBody()
52 1
                ->getContents();
53
    }
54
55
    /**
56
     * Creates an externalsign request.
57
     *
58
     * @param  Request $request
59
     * @return \Illuminate\Http\Response
60
     */
61 1
    public function store(Request $request)
62
    {
63 1
        $this->validate($request, [
64 1
            'description' => 'required|string|min:1|max:255',
65
            'ext_doc_id' => 'required|string|min:1|max:255',
66
            'file_content' => 'required|string',
67
            'filename' => 'required|string|min:1|max:255',
68
            // unique ref is nothing but the signee ref returned
69
            // by signere when a receiver is created
70
            'signee_refs.*.unique_ref' => 'required|string|size:36',
71
            'signee_refs.*.first_name' => 'required|string|min:1|max:255',
72
            'signee_refs.*.last_name' => 'required|string|min:1|max:255',
73
            'signee_refs.*.email' => 'required|email|min:1|max:255',
74
            'title' => 'required|string|min:1|max:255',
75
        ]);
76
77 1
        $body = [];
78
79
        // this is used to only set the keys which have been sent in
80 1
        $body['Description'] = $request->description;
81 1
        $body['ExternalDocumentId'] = $request->ext_doc_id;
82 1
        $body['FileContent'] = $request->file_content;
0 ignored issues
show
Bug introduced by
The property file_content does not seem to exist. Did you mean content?

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...
83 1
        $body['Filename'] = $request->filename;
84 1
        $body['Title'] = $request->title;
85
86 1
        $body['SigneeRefs'] = [];
87
88
        // populate the signee references
89 1 View Code Duplication
        foreach ($request->signee_refs as $signee) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
90
            // append this to the body
91 1
            $body['SigneeRefs'][] = [
92 1
                'UniqueRef' => $signee['unique_ref'],
93 1
                'FirstName' => $signee['first_name'],
94 1
                'LastName' => $signee['last_name'],
95 1
                'Email' => $signee['email'],
96
            ];
97
        }
98
99
        // populate the callback URLs
100 1
        $body['ReturnUrlError'] = Config::get('signere.sign_error_url');
101 1
        $body['ReturnUrlSuccess'] = Config::get('signere.sign_success_url');
102 1
        $body['ReturnUrlUserAbort'] = Config::get('signere.sign_cancel_url');
103
104 1
        return $this->extSign->createRequest($body)
105 1
                ->getBody()
106 1
                ->getContents();
107
    }
108
}
109