MultiCurrencyException   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 7 1
1
<?php
2
3
namespace hipanel\modules\finance\cart;
4
5
use hiqdev\yii2\cart\NotPurchasableException;
6
use Yii;
7
8
final class MultiCurrencyException extends NotPurchasableException
9
{
10
    public function resolve(): bool
11
    {
12
        Yii::error('Cart position "' . $this->position->getName() . '" was removed from the cart because multi-currency cart is not available for now', 'hipanel.cart');
13
        $this->cart->remove($this->position);
0 ignored issues
show
Bug introduced by
It seems like $this->position can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
14
15
        return true;
16
    }
17
}
18