Completed
Pull Request — master (#20)
by Klochok
11:43
created

RelatedPosition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hiqdev\yii2\cart;
4
5
use hipanel\modules\finance\logic\Calculator;
6
use yii\base\Widget;
7
use hiqdev\yii2\cart\ShoppingCart;
8
use hiqdev\yii2\cart\CartPositionInterface;
9
use Yii;
10
11
abstract class RelatedPosition implements RelatedPositionInterface
12
{
13
    /** @var CartPositionInterface */
14
    public $mainPosition;
15
16
    /** @var ShoppingCart */
17
    public $cart;
18
19
    public function __construct(CartPositionInterface $mainPosition)
20
    {
21
        $this->cart = Module::getInstance()->getCart();
22
        $this->mainPosition = $mainPosition;
23
    }
24
25
    /** @inheritDoc */
26
    public function render(): string
27
    {
28
        return $this->getWidget()->run();
29
    }
30
31
    public function calculate(CartPositionInterface $position): CartPositionInterface
32
    {
33
        $calculator = new Calculator([$position]);
34
        $calculationId = $position->getCalculationModel()->calculation_id;
0 ignored issues
show
Bug introduced by
The method getCalculationModel() does not seem to exist on object<hiqdev\yii2\cart\CartPositionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        $calculation = $calculator->getCalculation($calculationId);
36
        $value = $calculation->forCurrency($this->cart->getCurrency());
37
        $position->setPrice($value->price);
0 ignored issues
show
Bug introduced by
The method setPrice() does not seem to exist on object<hiqdev\yii2\cart\CartPositionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        $position->setValue($value->value);
0 ignored issues
show
Bug introduced by
The method setValue() does not seem to exist on object<hiqdev\yii2\cart\CartPositionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        $position->setCurrency($value->currency);
0 ignored issues
show
Bug introduced by
The method setCurrency() does not seem to exist on object<hiqdev\yii2\cart\CartPositionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        return $position;
42
    }
43
44
}
45