ActionResponse::openInNewTab()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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