Completed
Push — master ( 7a82a2...eef030 )
by Pavel
02:12
created

IndexAction::getQueryProperty()   A

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 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php namespace Pz\Doctrine\Rest\Action;
2
3
use Doctrine\Common\Collections\Criteria;
4
use Pz\Doctrine\Rest\BuilderChain\CriteriaChain;
5
use Pz\Doctrine\Rest\QueryParser\FilterableQueryParser;
6
use Pz\Doctrine\Rest\QueryParser\PropertyQueryParser;
7
use Pz\Doctrine\Rest\RestRequestAbstract;
8
use Pz\Doctrine\Rest\RestResponse;
9
10
class IndexAction extends RestActionAbstract
11
{
12
    /**
13
     * Entity alias.
14
     *
15
     * @var string
16
     */
17
    protected $rootAlias;
18
19
    /**
20
     * @param RestRequestAbstract $request
21
     *
22
     * @return RestResponse
23
     */
24 3
    public function handle(RestRequestAbstract $request)
25
    {
26 3
        $request->authorize($this->repository()->getClassName());
27 2
        $chain = CriteriaChain::create($this->criteriaBuilders($request));
28
29 2
        $criteria = new Criteria(null,
30 2
            $request->getOrderBy(),
31 2
            $request->getStart(),
32 2
            $request->getLimit()
33
        );
34
35 2
        $qb = $this->repository()
36 2
            ->createQueryBuilder($this->repository()->alias())
37 2
            ->addCriteria($chain->process($criteria));
38
39 2
        return $this->response()->index($request, $qb);
40
    }
41
42
    /**
43
     * @param RestRequestAbstract $request
44
     *
45
     * @return array
46
     */
47 2
    protected function criteriaBuilders(RestRequestAbstract $request)
48
    {
49
        return [
50 2
            new PropertyQueryParser($request, $this->getQueryProperty()),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getQueryProperty() targeting Pz\Doctrine\Rest\Action\...ion::getQueryProperty() 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...
51 2
            new FilterableQueryParser($request, $this->getFilterable()),
52
        ];
53
    }
54
55
    /**
56
     * Param that can be filtered if query is string.
57
     *
58
     * @return null|string
59
     */
60 2
    protected function getQueryProperty()
61
    {
62 2
        return null;
63
    }
64
65
    /**
66
     * Get list of filterable entity properties.
67
     *
68
     * @return array
69
     */
70 2
    protected function getFilterable()
71
    {
72 2
        return [];
73
    }
74
}
75