Completed
Push — master ( 671383...5c8721 )
by Antonio Carlos
04:32 queued 02:15
created

ErrorBag   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 36
rs 10

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
7
trait ErrorBag
8
{
9
    /**
10
     * Create an error bag and store a message on int.
11
     *
12
     * @param $message
13
     *
14
     * @return MessageBag
15
     */
16
    protected function createErrorBagForMessage($message)
17
    {
18
        return new MessageBag([
19
            'message' => $message,
20
        ]);
21
    }
22
23
    /**
24
     * Get a message bag with a message for a particular status code.
25
     *
26
     * @param $statusCode
27
     *
28
     * @return MessageBag
29
     */
30
    protected function getErrorBagForStatusCode($statusCode)
31
    {
32
        return $this->createErrorBagForMessage(
33
            trans(
34
                config(
35
                    $statusCode == SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY
36
                        ? 'google2fa.error_messages.wrong_otp'
37
                        : 'unknown error'
38
                )
39
            )
40
        );
41
    }
42
}
43