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 ( 6839b1...b7c0e1 )
by James
02:06
created

ErrorBag::createErrorBagForMessage()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5.4042

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 5
cts 9
cp 0.5556
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 5.4042
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PragmaRX\Google2FALaravel\Support;
6
7
use Exception;
8
use Illuminate\Support\MessageBag;
9
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
10
11
/**
12
 * Trait ErrorBag
13
 */
14
trait ErrorBag
15
{
16
    /**
17
     * Create an error bag and store a message on int.
18
     *
19
     * @param $message
20
     *
21
     * @return MessageBag
22
     */
23 3
    protected function createErrorBagForMessage($message): MessageBag
24
    {
25 3
        if (is_object($message)) {
26
            try {
27
                $message = (string)$message;
28
            } catch (Exception $e) {
0 ignored issues
show
Unused Code introduced by
catch (\Exception $e) { ...ng) $e->getMessage(); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
29
                $message = (string)$e->getMessage();
30
            }
31
        }
32 3
        if (is_array($message)) {
33
            $message = (string)$message;
34
        }
35
36 3
        return new MessageBag(
37
            [
38 3
                'message' => $message,
39
            ]
40
        );
41
    }
42
43
    /**
44
     * Get a message bag with a message for a particular status code.
45
     *
46
     * @param $statusCode
47
     *
48
     * @return MessageBag
49
     */
50 3
    protected function getErrorBagForStatusCode($statusCode)
51
    {
52
        $errorMap = [
53 3
            SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY => 'google2fa.error_messages.wrong_otp',
54 3
            SymfonyResponse::HTTP_BAD_REQUEST          => 'google2fa.error_messages.cannot_be_empty',
55
        ];
56
57 3
        return $this->createErrorBagForMessage(
58 3
            trans(
59 3
                config(
60 3
                    array_key_exists($statusCode, $errorMap) ? $errorMap[$statusCode] : 'google2fa.error_messages.unknown'
61
                )
62
            )
63
        );
64
    }
65
}
66