Test Failed
Pull Request — develop (#41)
by Yuji
04:41
created

UpdateOrderInfoRequest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A api() 0 4 1
A response() 0 4 1
A validateParams() 0 3 1
A getParams() 0 10 1
A setIsSeen() 0 5 1
A setSuspect() 10 10 2
A setPayType() 10 10 2

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
namespace Shippinno\YahooShoppingJp\Request;
5
6
7
use FluidXml\FluidXml;
8
use LogicException;
9
use Shippinno\YahooShoppingJp\Api\UpdateOrderInfoApi;
10
use Shippinno\YahooShoppingJp\Enum\PayType;
11
use Shippinno\YahooShoppingJp\Enum\SuspectFlag;
12
use Shippinno\YahooShoppingJp\Response\UpdateOrderInfoResponse;
13
14
class UpdateOrderInfoRequest extends AbstractRequest
15
{
16
17
    /**
18
     * @return UpdateOrderInfoApi
19
     */
20
    public function api()
21
    {
22
        return new UpdateOrderInfoApi;
23
    }
24
25
    /**
26
     * @return UpdateOrderInfoResponse
27
     */
28
    public function response()
29
    {
30
        return new UpdateOrderInfoResponse;
31
    }
32
33
    /**
34
     * @return void
35
     */
36
    protected function validateParams()
37
    {
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getParams()
44
    {
45
        $this->setIsSeen();
46
        $this->validateParams();
47
48
        $fluidXml = new FluidXml('Req');
49
        $fluidXml->add($this->params);
50
51
        return $fluidXml->xml();
52
    }
53
54
    /**
55
     * 閲覧済みフラグ
56
     * 更新する時必ずtrue
57
     *
58
     * @return bool
59
     */
60
    public function setIsSeen(): self
61
    {
62
        $this->params['Order']['IsSeen'] = true;
63
        return $this;
64
    }
65
66
    /**
67
     * 悪戯フラグ
68
     *
69
     * @param SuspectFlag $suspectFlag
70
     * @return UpdateOrderInfoRequest
71
     */
72 View Code Duplication
    public function setSuspect(SuspectFlag $suspectFlag): self
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...
73
    {
74
        if (isset($this->params['Order']['Suspect'])) {
75
            throw new LogicException('Suspect is already set.');
76
        }
77
        $this->params['Order']['Suspect'] = $suspectFlag->getValue();
78
79
        return $this;
80
81
    }
82
83
    /**
84
     * 支払い分類
85
     *
86
     * @param PayType $payType
87
     * @return UpdateOrderInfoRequest
88
     */
89 View Code Duplication
    public function setPayType(PayType $payType): self
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...
90
    {
91
        if (isset($this->params['Order']['PayType'])) {
92
            throw new LogicException('PayType is already set.');
93
        }
94
        $this->params['Order']['PayType'] = $payType->getValue();
95
96
        return $this;
97
98
    }
99
}