ActionResponse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 8
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 5 1
A openInNewTab() 0 4 1
A redirect() 0 4 1
A response() 0 4 1
1
<?php
2
3
4
namespace UserAdmin\IndexPage\Actions;
5
6
use Illuminate\Support\Facades\Response;
7
8
class ActionResponse
9
{
10
    public static function message(string $text, string $type = 'success')
11
    {
12
        return static::response('message', [
13
            'content' => $text,
14
            'toast'   => $type,
15
        ]);
16
    }
17
18
    public static function redirect(string $url)
19
    {
20
        return static::response('redirect', [
21
            'content' => $url,
22
        ]);
23
    }
24
25
    public static function openInNewTab(string $url)
26
    {
27
        return static::response('new-tab', [
28
            'content' => $url,
29
        ]);
30
    }
31
32
    protected static function response(string $action, array $data = [])
33
    {
34
        return Response::json(array_merge($data, [
35
            'action' => $action,
36
        ]));
37
    }
38
}
39