ErrorPurchaseException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getName() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\cart;
12
13
use yii\base\Exception;
14
15
/**
16
 * Exception represents an exception occurred during cart position purchase.
17
 */
18 View Code Duplication
class ErrorPurchaseException extends Exception implements PositionFinishExceptionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * @var AbstractPurchase
22
     */
23
    public $purchase;
24
25
    /**
26
     * @var AbstractCartPosition
27
     */
28
    public $position;
29
30
    /**
31
     * ErrorPurchaseException constructor.
32
     *
33
     * @param string $message
34
     * @param AbstractPurchase $purchase
35
     * @param Exception $previous
36
     */
37
    public function __construct($message, $purchase, Exception $previous = null)
38
    {
39
        $this->purchase = $purchase;
40
        $this->position = $purchase->position;
41
42
        parent::__construct($message, 0, $previous);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getName()
49
    {
50
        return 'Error occurred during item "' . $this->purchase->position->getName() . '"" purchase';
51
    }
52
}
53