GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

VerifyClientController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 96
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A _createAuthenticationURL() 0 10 1
A createSSODataStructure() 0 10 1
A _checkForValidationRule() 0 11 2
B verifyClient() 0 38 6
1
<?php
2
3
namespace bSecure\UniversalCheckout\Controllers\SSO;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
8
//Helper
9
use bSecure\UniversalCheckout\Helpers\AppException;
0 ignored issues
show
Bug introduced by
The type bSecure\UniversalCheckout\Helpers\AppException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use bSecure\UniversalCheckout\Helpers\Constant;
11
use bSecure\UniversalCheckout\Helpers\ApiResponseHandler;
12
use bSecure\UniversalCheckout\Helpers\Helper;
13
14
//Facade
15
use Validator;
0 ignored issues
show
Bug introduced by
The type Validator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
class VerifyClientController extends Controller
18
{
19
20
    /**
21
     * Author: Sara Hasan
22
     * Date: 26-November-2020
23
     */
24
    public function verifyClient($state,$appType)
25
    {
26
        try {
27
28
            $validationErrors = $this->_checkForValidationRule( $state );
29
30
            if( count( $validationErrors ) > 0 )
31
            {
32
                return ApiResponseHandler::validationError( $validationErrors );
33
            }
34
35
36
            $ssoPayload = $this->createSSODataStructure($state);
37
38
            if($appType == Constant::APP_TYPE['checkout'])
39
            {
40
                $auth_url = $this->_createAuthenticationURL($ssoPayload);
41
                $response = [
42
                  'redirect_url' => $auth_url
43
                ];
44
                return ApiResponseHandler::success($response, trans('bSecure::messages.sso_sco.success'));
0 ignored issues
show
Bug introduced by
The function trans was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
                return ApiResponseHandler::success($response, /** @scrutinizer ignore-call */ trans('bSecure::messages.sso_sco.success'));
Loading history...
45
            }
46
            else if ($appType == Constant::APP_TYPE['sdk'])
47
            {
48
                $ssoResponse = Helper::verifyClient($ssoPayload);
49
                if($ssoResponse['error'])
50
                {
51
                    return ApiResponseHandler::failure($ssoResponse['message']);
52
                }else{
53
                    $response = $ssoResponse['body'];
54
                    return ApiResponseHandler::success($response, trans('bSecure::messages.sso_sco.success'));
55
                }
56
            }else{
57
                return ApiResponseHandler::failure('Invalid application type', []);
58
            }
59
60
        } catch (\Exception $e) {
61
            return ApiResponseHandler::failure(trans('bSecure::messages.sso_sco.failure'), $e->getTraceAsString());
62
        }
63
    }
64
65
    /**
66
     * Author: Sara Hasan
67
     * Date: 26-November-2020
68
     */
69
    private function createSSODataStructure($state)
70
    {
71
        $sso_client = [];
72
73
        $sso_client['client_id'] = config('bSecure.client_id');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $sso_client['client_id'] = /** @scrutinizer ignore-call */ config('bSecure.client_id');
Loading history...
74
        $sso_client['scope'] = "profile";
75
        $sso_client['response_type'] = "code";
76
        $sso_client['state'] = $state;
77
78
        return $sso_client;
79
    }
80
81
    /**
82
     * Author: Sara Hasan
83
     * Date: 27-November-2020
84
     */
85
    private function _createAuthenticationURL($sso_client)
86
    {
87
        $login_app_url = Constant::LOGIN_REDIRECT_URL;
88
89
        $client_id = $sso_client['client_id'];
90
        $scope = $sso_client['scope'];
91
        $response_type = $sso_client['response_type'];
92
        $state = $sso_client['state'];
93
94
        return $login_app_url.'?scope='.$scope.'&response_type='.$response_type.'&client_id='.$client_id.'&state='.$state;
95
    }
96
97
98
    /**
99
     * Author: Sara Hasan
100
     * Date: 27-November-2020
101
     */
102
    private function _checkForValidationRule($state )
103
    {
104
        $errors = [];
105
106
107
        if( empty($state) )
108
        {
109
            $errors[] = trans('bSecure::messages.validation.state.required');
0 ignored issues
show
Bug introduced by
The function trans was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
            $errors[] = /** @scrutinizer ignore-call */ trans('bSecure::messages.validation.state.required');
Loading history...
110
        }
111
112
        return $errors;
113
    }
114
}
115