Completed
Push — master ( f3d932...88ba9b )
by Dmitry
03:14
created

SearchHandler::getQueryOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
namespace hiapi\commands;
4
5
use hiapi\query\Specification;
6
use hiapi\repositories\BaseRepository;
7
use Yii;
8
9
class SearchHandler
10
{
11
    public function handle(SearchCommand $command)
12
    {
13
        return $this->getRepository($command)->findAll($this->buildSpecification($command));
0 ignored issues
show
Documentation Bug introduced by
The method findAll does not exist on object<hiapi\repositories\BaseRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
14
    }
15
16
    protected function buildSpecification(SearchCommand $command)
17
    {
18
        return (new Specification())
19
            ->where($command->where)
20
            ->limit($command->limit ?: 25);
21
    }
22
23
    /**
24
     * @param SearchCommand $command
25
     * @return BaseRepository
26
     */
27
    protected function getRepository(SearchCommand $command)
28
    {
29
        return Yii::$app->entityManager->getRepository($command->getEntityClass());
30
    }
31
32
    protected function getQueryOptions(SearchCommand $command)
33
    {
34
        return [
35
            'where' => $command->where,
36
            'limit' => $command->limit ?: 25,
37
        ];
38
    }
39
}
40