Completed
Pull Request — master (#20)
by Klochok
19:23 queued 04:30
created

RelatedPosition::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace hiqdev\yii2\cart;
4
5
use yii\base\Widget;
6
use hiqdev\yii2\cart\ShoppingCart;
7
use Yii;
8
9
abstract class RelatedPosition implements RelatedPositionInterface
10
{
11
    /** @var Widget */
12
    public $widget;
13
14
    /** @var CartPositionInterface */
15
    public $mainPosition;
16
17
    /** @var ShoppingCart */
18
    public $cart;
19
20
    public function __construct(ShoppingCart $cart, CartPositionInterface $mainPosition)
21
    {
22
        $this->cart = $cart;
23
        $this->mainPosition = $mainPosition;
24
    }
25
26
    /** @inheritDoc */
27
    public function setWidget($className, array $params = []): RelatedPositionInterface
28
    {
29
        $this->widget = Yii::createObject(array_merge($params, [
30
            'class' => $className,
31
            'relatedPosition' => $this->getRelatedPosition(),
32
            'mainPosition' => $this->mainPosition,
33
            'cart' => $this->cart,
34
        ]));
35
36
        return $this;
37
    }
38
39
    /** @inheritDoc */
40
    public function render(): string
41
    {
42
        return $this->widget->run();
43
    }
44
}
45