Completed
Pull Request — master (#20)
by Klochok
10:28
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
7
abstract class RelatedPosition implements RelatedPositionInterface
8
{
9
    /** @var CartPositionInterface */
10
    public $mainPosition;
11
12
    /** @var ShoppingCart */
13
    public $cart;
14
15
    public function __construct(CartPositionInterface $mainPosition)
16
    {
17
        $this->cart = Module::getInstance()->getCart();
18
        $this->mainPosition = $mainPosition;
19
    }
20
21
    /** @inheritDoc */
22
    public function render(): string
23
    {
24
        return $this->getWidget()->run();
25
    }
26
27
    public function calculate(CartPositionInterface $position): CartPositionInterface
28
    {
29
        $calculator = new Calculator([$position]);
30
        $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...
31
        $calculation = $calculator->getCalculation($calculationId);
32
        $value = $calculation->forCurrency($this->cart->getCurrency());
33
        $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...
34
        $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...
35
        $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...
36
37
        return $position;
38
    }
39
40
}
41