Completed
Push — master ( 09c84d...fe53c9 )
by Dmitry
02:55
created

SearchHandler::buildQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace hiapi\commands;
4
5
use hiapi\repositories\ActiveQuery;
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)->find($this->buildQuery($command))->all();
14
    }
15
16
    protected function buildQuery(SearchCommand $command)
17
    {
18
        $recordClass = $this->getRepository($command)->getRecordClass();
19
20
        return new ActiveQuery($recordClass, $command->getQueryOptions());
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