Passed
Push — master ( e32a81...12baf4 )
by Antonio Carlos
02:26
created

src/Checkers/Docusign.php (7 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PragmaRX\Health\Checkers;
4
5
use DomainException;
6
use DocuSign\eSign\ApiClient;
7
use DocuSign\eSign\Configuration;
8
use PragmaRX\Health\Support\Result;
9
use DocuSign\eSign\Api\AuthenticationApi;
10
use DocuSign\eSign\Api\AuthenticationApi\LoginOptions;
11
12
class Docusign extends Base
13
{
14
    /**
15
     * @return Result
16
     */
17 1
    public function check()
18
    {
19 1
        if ($this->docusignIsNotInstalled()) {
20
            return $this->makeResult(false, $this->target->notInstalledMessage);
0 ignored issues
show
The property notInstalledMessage does not seem to exist in PragmaRX\Health\Support\Target.

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...
21
        }
22
23 1
        if (! $this->login()) {
24
            throw new DomainException(
25
                'Unable to authenticate to the DocuSign Api'
26
            );
27
        }
28
29
        return $this->makeHealthyResult();
30
    }
31
32 1
    private function docusignIsNotInstalled()
33
    {
34 1
        return ! class_exists(ApiClient::class);
35
    }
36
37
    private function getAccountIdFromLogin($login)
38
    {
39
        return $login->getLoginAccounts()[0]->getAccountId();
40
    }
41
42
    /**
43
     * @param $config
44
     * @return ApiClient
45
     */
46 1
    protected function getApiClient($config)
47
    {
48 1
        return new ApiClient($config);
49
    }
50
51
    /**
52
     * @param $config
53
     * @return AuthenticationApi
54
     */
55 1
    protected function getAuthApi($config)
56
    {
57 1
        return new AuthenticationApi($this->getApiClient($config));
58
    }
59
60
    /**
61
     * @return ApiClient
62
     */
63 1
    protected function getConfig()
64
    {
65 1
        return (new Configuration())
66 1
            ->setDebug($this->target->debug)
0 ignored issues
show
The property debug does not seem to exist in PragmaRX\Health\Support\Target.

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...
67 1
            ->setDebugFile($this->makeFileName($this->target->debugFile))
0 ignored issues
show
The property debugFile does not seem to exist in PragmaRX\Health\Support\Target.

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...
68 1
            ->setHost($this->target->apiHost)
0 ignored issues
show
The property apiHost does not seem to exist in PragmaRX\Health\Support\Target.

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...
69 1
            ->addDefaultHeader(
70 1
                'X-DocuSign-Authentication',
71 1
                json_encode([
72 1
                    'Username' => $this->target->username,
0 ignored issues
show
The property username does not seem to exist in PragmaRX\Health\Support\Target.

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...
73 1
                    'Password' => $this->target->password,
0 ignored issues
show
The property password does not seem to exist in PragmaRX\Health\Support\Target.

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...
74 1
                    'IntegratorKey' => $this->target->integratorKey,
0 ignored issues
show
The property integratorKey does not seem to exist in PragmaRX\Health\Support\Target.

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...
75
                ])
76
            );
77
    }
78
79
    /**
80
     * @param $config
81
     * @return \DocuSign\eSign\Model\LoginInformation
82
     */
83 1
    protected function getLoginInformation($config)
84
    {
85 1
        return $this->getAuthApi($config)->login($this->getLoginOptions());
86
    }
87
88
    /**
89
     * @return LoginOptions
90
     */
91 1
    protected function getLoginOptions()
92
    {
93 1
        return new LoginOptions();
94
    }
95
96
    /**
97
     * @return mixed
98
     */
99 1
    protected function login()
100
    {
101 1
        return $this->getAccountIdFromLogin(
102 1
            $this->getLoginInformation($this->getConfig())
103
        );
104
    }
105
106 1
    private function makeFileName($file)
107
    {
108 1
        if (is_absolute_path($file)) {
109
            return $file;
110
        }
111
112 1
        return base_path($file);
113
    }
114
}
115