Completed
Push — master ( dbaf03...a19a70 )
by Andrii
14:13
created

PlanRepository::old___findAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 2
1
<?php
2
3
namespace hiqdev\billing\hiapi\plan;
4
5
use hiapi\components\ConnectionInterface;
6
use hiapi\query\Specification;
7
use hiapi\repositories\BaseRepository;
8
use hiqdev\php\billing\customer\Customer;
9
use hiqdev\php\billing\plan\PlanFactoryInterface;
10
use hiqdev\php\billing\plan\PlanRepositoryInterface;
11
use hiqdev\php\billing\action\ActionInterface;
12
use hiqdev\php\billing\order\OrderInterface;
13
use Yii;
14
use yii\db\Query;
15
16
class PlanRepository extends BaseRepository implements PlanRepositoryInterface
17
{
18
    public $queryClass = PlanQuery::class;
19
20
    /**
21
     * @var PlanFactory
22
     */
23
    protected $factory;
24
25
    public function __construct(
26
        ConnectionInterface $db,
27
        PlanFactoryInterface $factory,
28
        array $config = []
29
    ) {
30
        parent::__construct($config);
31
32
        $this->db = $db;
33
        $this->factory = $factory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $factory of type object<hiqdev\php\billin...n\PlanFactoryInterface> is incompatible with the declared type object<hiqdev\billing\hiapi\plan\PlanFactory> of property $factory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    public function create(array $row)
37
    {
38
        $row['seller'] = $this->createEntity(Customer::class, $row['seller']);
39
40
        return parent::create($row);
41
    }
42
43
    public function findByAction(ActionInterface $action)
44
    {
45
        $client_id = $action->getCustomer()->getId();
46
        $seller = $action->getCustomer()->getSeller()->getLogin();
47
        $type = $action->getTarget()->getType();
48
49
        $spec = Yii::createObject(Specification::class)
50
            ->with(Price::class)
51
            ->where([
52
                'type-name' => $type,
53
                'available_for' => [
54
                    'client_id' => $client_id,
55
                    'seller'    => $seller,
56
                ],
57
            ])
58
        ;
59
60
        return $this->findOne($spec);
61
    }
62
63
    public function findByOrder(OrderInterface $order)
64
    {
65
        return array_map([$this, 'findByAction'], $order->getActions());
66
    }
67
}
68