Completed
Push — master ( 88ba9b...8a3d51 )
by Andrii
03:03
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));
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