Completed
Push — master ( bfe327...f8a59f )
by Dmitry
05:34
created

PlanRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A findAll() 0 17 2
1
<?php
2
3
namespace hiqdev\billing\hiapi\repositories;
4
5
use hiapi\components\ConnectionInterface;
6
use hiapi\query\QueryMutator;
7
use hiapi\query\Specification;
8
use yii\db\Query;
9
10
class PlanRepository extends \hiapi\repositories\BaseRepository
11
{
12
    /**
13
     * @var ConnectionInterface
14
     */
15
    private $db;
16
    /**
17
     * @var PlanFactory
18
     */
19
    private $planFactory;
20
    /**
21
     * @var PlanHydrator
22
     */
23
    private $planHydrator;
24
25
    public function __construct(ConnectionInterface $db, PlanFactory $planFactory, PlanHydrator $planHydrator, array $config = [])
26
    {
27
        parent::__construct($config);
28
29
        $this->db = $db;
30
        $this->planFactory = $planFactory;
31
        $this->planHydrator = $planHydrator;
32
    }
33
34
    public function findAll(Specification $specification)
35
    {
36
        $mutator = (new QueryMutator((new Query())
37
            ->select(['p.obj_id as id', 'p.name'])
38
            ->from('tariff p')
39
        ))->apply($specification);
40
41
        $rows = $mutator->getQuery()->createCommand($this->db)->queryAll();
42
43
        foreach ($specification->requestedRelations as $relation => $todo) {
0 ignored issues
show
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
44
            // todo...
45
        }
46
47
        $plans = $this->planHydrator->hydrateMultiple($this->planFactory->createPrototype(), $rows);
48
49
        return $plans;
50
    }
51
}
52