Completed
Push — master ( 1d3c0c...8bf0fe )
by Song
03:06
created

Delete   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A handle() 0 15 2
A dialog() 0 4 1
1
<?php
2
3
namespace Encore\Admin\Grid\Actions;
4
5
use Encore\Admin\Actions\Response;
6
use Encore\Admin\Actions\RowAction;
7
use Illuminate\Database\Eloquent\Model;
8
9
class Delete extends RowAction
10
{
11
    /**
12
     * @return array|null|string
13
     */
14
    public function name()
15
    {
16
        return __('admin.delete');
0 ignored issues
show
Bug Compatibility introduced by
The expression __('admin.delete'); of type string|array|null adds the type array to the return on line 16 which is incompatible with the return type of the parent method Encore\Admin\Actions\Action::name of type string.
Loading history...
17
    }
18
19
    /**
20
     * @param Model $model
21
     *
22
     * @return Response
23
     */
24
    public function handle(Model $model)
25
    {
26
        $trans = [
27
            'failed'    => trans('admin.delete_failed'),
28
            'succeeded' => trans('admin.delete_succeeded'),
29
        ];
30
31
        try {
32
            $model->delete();
33
        } catch (\Exception $exception) {
34
            return $this->getResponse()->error("{$trans['failed']} : {$exception->getMessage()}");
0 ignored issues
show
Bug introduced by
The method getResponse() does not exist on Encore\Admin\Grid\Actions\Delete. Did you maybe mean response()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
        }
36
37
        return $this->getResponse()->success($trans['succeeded'])->refresh();
0 ignored issues
show
Bug introduced by
The method getResponse() does not exist on Encore\Admin\Grid\Actions\Delete. Did you maybe mean response()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
38
    }
39
40
    /**
41
     * @return void
42
     */
43
    public function dialog()
44
    {
45
        $this->question(trans('admin.delete_confirm'), ['confirmButtonColor' => '#d33']);
46
    }
47
}