Completed
Push — sf/csv-headers ( 829ce9...de2c5f )
by Kiyotaka
06:12
created

InvalidItemException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getMessageArgs() 0 4 1
A isWarning() 0 4 1
A fromProductClass() 0 12 3
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
19
{
20
    private $messageArgs = [];
21
22
    private $warning;
23
24
    public function __construct($message = null, $messageArgs = [], $warning = false)
25
    {
26
        parent::__construct($message);
27
        $this->messageArgs = $messageArgs;
28
        $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
    public function isWarning()
43
    {
44
        return $this->warning;
45
    }
46
47
    /**
48
     * @return InvalidItemException
49
     */
50
    public static function fromProductClass($errorMessage, ProductClass $ProductClass)
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