RestController::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php namespace Pz\LaravelDoctrine\Rest;
2
3
use Illuminate\Routing\Controller;
4
use League\Fractal\TransformerAbstract;
5
use Pz\Doctrine\Rest\RestRepository;
6
use Pz\LaravelDoctrine\Rest\Action\CreateAction;
7
use Pz\LaravelDoctrine\Rest\Action\DeleteAction;
8
use Pz\LaravelDoctrine\Rest\Action\IndexAction;
9
use Pz\LaravelDoctrine\Rest\Action\ShowAction;
10
use Pz\LaravelDoctrine\Rest\Action\UpdateAction;
11
12
class RestController extends Controller
13
{
14
    /**
15
     * @var TransformerAbstract
16
     */
17
    protected $transformer;
18
19
    /**
20
     * @var RestRepository
21
     */
22
    protected $repository;
23
24
    /**
25
     * @param RestRequest $request
26
     *
27
     * @return \Pz\Doctrine\Rest\RestResponse
28
     */
29 4
    public function index(RestRequest $request)
30
    {
31 4
        return (new IndexAction($this->repository(), $this->transformer()))
32 4
            ->setFilterProperty($this->getFilterProperty())
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getFilterProperty() targeting Pz\LaravelDoctrine\Rest\...er::getFilterProperty() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
33 4
            ->setFilterable($this->getFilterable())
34 4
            ->dispatch($request);
35
    }
36
37
    /**
38
     * @param RestRequest $request
39
     *
40
     * @return \Pz\Doctrine\Rest\RestResponse
41
     */
42 3
    public function create(RestRequest $request)
43
    {
44 3
        return (new CreateAction($this->repository(), $this->transformer()))->dispatch($request);
45
    }
46
47
    /**
48
     * @param RestRequest $request
49
     *
50
     * @return \Pz\Doctrine\Rest\RestResponse
51
     */
52 6
    public function show(RestRequest $request)
53
    {
54 6
        return (new ShowAction($this->repository(), $this->transformer()))->dispatch($request);
55
    }
56
57
    /**
58
     * @param RestRequest $request
59
     *
60
     * @return \Pz\Doctrine\Rest\RestResponse
61
     */
62 3
    public function update(RestRequest $request)
63
    {
64 3
        return (new UpdateAction($this->repository(), $this->transformer()))->dispatch($request);
65
    }
66
67
    /**
68
     * @param RestRequest $request
69
     *
70
     * @return \Pz\Doctrine\Rest\RestResponse
71
     */
72 3
    public function delete(RestRequest $request)
73
    {
74 3
        return (new DeleteAction($this->repository(), $this->transformer()))->dispatch($request);
75
    }
76
77
    /**
78
     * Param that can be filtered if query is string.
79
     *
80
     * @return null|string
81
     */
82 4
    protected function getFilterProperty()
83
    {
84 4
        return null;
85
    }
86
87
    /**
88
     * Get list of filterable entity properties.
89
     *
90
     * @return array
91
     */
92 4
    protected function getFilterable()
93
    {
94 4
        return [];
95
    }
96
97
    /**
98
     * @return TransformerAbstract
99
     */
100 7
    protected function transformer()
101
    {
102 7
        return $this->transformer;
103
    }
104
105
    /**
106
     * @return RestRepository
107
     */
108 8
    protected function repository()
109
    {
110 8
        return $this->repository;
111
    }
112
}
113