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

SearchHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 23
ccs 0
cts 9
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
A buildQuery() 0 6 1
A getRepository() 0 4 1
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