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

SearchHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
ccs 0
cts 14
cp 0
rs 10

4 Methods

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