Completed
Push — master ( b0d73a...d2854c )
by Song
02:52
created

ModelForm   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 4 1
A destroy() 0 14 2
A store() 0 4 1
1
<?php
2
3
namespace Encore\Admin\Controllers;
4
5
trait ModelForm
6
{
7
    /**
8
     * Update the specified resource in storage.
9
     *
10
     * @param int $id
11
     *
12
     * @return \Illuminate\Http\Response
13
     */
14
    public function update($id)
15
    {
16
        return $this->form()->update($id);
0 ignored issues
show
Bug introduced by
It seems like form() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
17
    }
18
19
    /**
20
     * Remove the specified resource from storage.
21
     *
22
     * @param int $id
23
     *
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function destroy($id)
27
    {
28
        if ($this->form()->destroy($id)) {
0 ignored issues
show
Bug introduced by
It seems like form() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
29
            return response()->json([
30
                'status'  => true,
31
                'message' => trans('admin.delete_succeeded'),
32
            ]);
33
        } else {
34
            return response()->json([
35
                'status'  => false,
36
                'message' => trans('admin.delete_failed'),
37
            ]);
38
        }
39
    }
40
41
    /**
42
     * Store a newly created resource in storage.
43
     *
44
     * @return \Illuminate\Http\Response
45
     */
46
    public function store()
47
    {
48
        return $this->form()->store();
0 ignored issues
show
Bug introduced by
It seems like form() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
    }
50
}
51