Completed
Pull Request — master (#121)
by Dmitry
07:20
created

MultiCurrencyException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 29
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A resolve() 0 7 1
1
<?php
2
3
namespace hipanel\modules\finance\cart;
4
5
use hiqdev\yii2\cart\ShoppingCart;
6
use Yii;
7
8
final class MultiCurrencyException extends NotPurchasableException
9
{
10
    /**
11
     * @var AbstractCartPosition
12
     */
13
    private $position;
14
    /**
15
     * @var ShoppingCart
16
     */
17
    private $shoppingCart;
18
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function __construct(string $message, ShoppingCart $shoppingCart, AbstractCartPosition $position)
23
    {
24
        parent::__construct($message ?: 'Can not add this item to cart because of different currency');
25
        $this->position = $position;
26
        $this->shoppingCart = $shoppingCart;
27
    }
28
29
    public function resolve(): bool
30
    {
31
        Yii::error('Cart position "' . $this->position->getName() . '" was removed from the cart because multi-currency cart is not available for now', 'hipanel.cart');
32
        $this->shoppingCart->remove($this->position);
33
34
        return true;
35
    }
36
}
37