Completed
Push — master ( 241ec6...70b488 )
by Antonio Carlos
04:26
created

ErrorBag   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 36
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createErrorBagForMessage() 0 6 1
A getErrorBagForStatusCode() 0 12 2
1
<?php
2
3
namespace PragmaRX\Google2FALaravel\Support;
4
5
use Illuminate\Support\MessageBag;
6
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
7
8
trait ErrorBag
9
{
10
    /**
11
     * Create an error bag and store a message on int.
12
     *
13
     * @param $message
14
     *
15
     * @return MessageBag
16
     */
17
    protected function createErrorBagForMessage($message)
18
    {
19
        return new MessageBag([
20
            'message' => $message,
21
        ]);
22
    }
23
24
    /**
25
     * Get a message bag with a message for a particular status code.
26
     *
27
     * @param $statusCode
28
     *
29
     * @return MessageBag
30
     */
31
    protected function getErrorBagForStatusCode($statusCode)
32
    {
33
        return $this->createErrorBagForMessage(
34
            trans(
35
                config(
36
                    $statusCode == SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY
37
                        ? 'google2fa.error_messages.wrong_otp'
38
                        : 'unknown error'
39
                )
40
            )
41
        );
42
    }
43
}
44