Completed
Pull Request — experimental/sf (#3265)
by Kiyotaka
41:07 queued 06:58
created

InvalidItemException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
dl 12
loc 45
ccs 6
cts 15
cp 0.4
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMessageArgs() 0 4 1
A isWarning() 0 4 1
A fromProductClass() 12 12 3

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
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service\PurchaseFlow;
15
16
use Eccube\Entity\ProductClass;
17
18
class InvalidItemException extends \Exception
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
19
{
20
    private $messageArgs = [];
21
22
    private $warning;
23
24 72
    public function __construct($message = null, $messageArgs = [], $warning = false)
25
    {
26 72
        parent::__construct($message);
27 72
        $this->messageArgs = $messageArgs;
28 72
        $this->warning = $warning;
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function getMessageArgs()
35
    {
36
        return $this->messageArgs;
37
    }
38
39
    /**
40
     * @return bool
41
     */
42 14
    public function isWarning()
43
    {
44 14
        return $this->warning;
45
    }
46
47
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$errorMessage" missing
Loading history...
introduced by
Doc comment for parameter "$ProductClass" missing
Loading history...
48
     * @return InvalidItemException
49
     */
50 View Code Duplication
    public static function fromProductClass($errorMessage, ProductClass $ProductClass)
0 ignored issues
show
Duplication introduced by
This method 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...
51
    {
52
        $productName = $ProductClass->getProduct()->getName();
53
        if ($ProductClass->hasClassCategory1()) {
54
            $productName .= ' - '.$ProductClass->getClassCategory1()->getName();
55
        }
56
        if ($ProductClass->hasClassCategory2()) {
57
            $productName .= ' - '.$ProductClass->getClassCategory2()->getName();
58
        }
59
60
        return new self($errorMessage, ['%product%' => $productName]);
61
    }
62
}
63