Passed
Push — develop ( 4cbaa0...09ba9e )
by Ngoding
05:32
created

RedirectResponseProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Http\RedirectResponse;
6
use Illuminate\Support\ServiceProvider;
7
8
class RedirectResponseProvider extends ServiceProvider
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13
    public function register()
14
    {
15
        //
16
    }
17
18
    /**
19
     * Bootstrap services.
20
     *
21
     * @return void
22
     */
23 18
    public function boot()
24
    {
25 18
        RedirectResponse::macro('withAlert', function (string $type, string $message) {
26
            /** @var \Illuminate\Http\RedirectResponse $redirectResponse */
27 1
            $redirectResponse = $this;
28
29 1
            $type = 'alert-' . $type;
30 1
            $alert = compact('type', 'message');
31
32 1
            return $redirectResponse->with(compact('alert'));
33
        });
34
35 18
        RedirectResponse::macro('withAlertSuccess', function (string $message) {
36
            /** @var \Illuminate\Http\RedirectResponse $redirectResponse */
37 1
            $redirectResponse = $this;
38
39 1
            return $redirectResponse->withAlert('success', $message);
40
        });
41
    }
42
}
43