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.
Completed
Push — master ( c4a10f...5fd32e )
by James
01:57
created

Response::getRequest()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace PragmaRX\Google2FALaravel\Support;
4
5
use Illuminate\Http\JsonResponse as IlluminateJsonResponse;
6
use Illuminate\Http\Response as IlluminateHtmlResponse;
7
use PragmaRX\Google2FALaravel\Events\OneTimePasswordRequested;
8
use PragmaRX\Google2FALaravel\Events\OneTimePasswordRequested53;
9
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
10
11
/**
12
 * Trait Response
13
 */
14
trait Response
15
{
16
    /**
17
     * Make a JSON response.
18
     *
19
     * @param $statusCode
20
     *
21
     * @return IlluminateJsonResponse
22
     */
23
    protected function makeJsonResponse($statusCode)
24
    {
25
        return new IlluminateJsonResponse(
26
            $this->getErrorBagForStatusCode($statusCode),
27
            $statusCode
28
        );
29
    }
30
31
    /**
32
     * Make the status code, to respond accordingly.
33
     *
34
     * @return int
35
     */
36
    protected function makeStatusCode()
37
    {
38
        if ($this->getRequest()->isMethod('get') || ($this->checkOTP() === Constants::OTP_VALID)) {
39
            return SymfonyResponse::HTTP_OK;
40
        }
41
42
        if ($this->checkOTP() === Constants::OTP_EMPTY) {
43
            return SymfonyResponse::HTTP_BAD_REQUEST;
44
        }
45
46
        return SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY;
47
    }
48
49
    /**
50
     * Make a web response.
51
     *
52
     * @param $statusCode
53
     *
54
     * @return \Illuminate\Http\Response
55
     */
56
    protected function makeHtmlResponse($statusCode)
57
    {
58
        $view = $this->getView();
59
60
        if ($statusCode !== SymfonyResponse::HTTP_OK) {
61
            $view->withErrors($this->getErrorBagForStatusCode($statusCode));
62
        }
63
64
        return new IlluminateHtmlResponse($view, $statusCode);
65
    }
66
67
    /**
68
     * Create a response to request the OTP.
69
     *
70
     * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
71
     */
72
    public function makeRequestOneTimePasswordResponse()
73
    {
74
        event(
75
            app()->version() < '5.4'
76
                ? new OneTimePasswordRequested53($this->getUser())
77
                : new OneTimePasswordRequested($this->getUser())
78
        );
79
80
        $expectJson = app()->version() < '5.4'
81
            ? $this->getRequest()->wantsJson()
82
            : $this->getRequest()->expectsJson();
83
84
        return $expectJson
85
            ? $this->makeJsonResponse($this->makeStatusCode())
86
            : $this->makeHtmlResponse($this->makeStatusCode());
87
    }
88
89
    /**
90
     * Get the OTP view.
91
     *
92
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
93
     */
94
    private function getView()
95
    {
96
        return view($this->config('view'));
97
    }
98
99
    abstract protected function getErrorBagForStatusCode($statusCode);
100
101
    abstract protected function inputHasOneTimePassword();
102
103
    abstract public function checkOTP();
104
105
    abstract protected function getUser();
106
107
    abstract public function getRequest();
108
109
    abstract protected function config($string, $children = []);
110
}
111