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

PlanRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

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 8
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
crap 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