GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DirectLinkPaymentRequestTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 109
Duplicated Lines 7.34 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 8
loc 109
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A IsValidWhenRequiredFieldsAreFilledIn() 0 5 1
A IsInvalidWhenFieldsAreMissing() 0 5 1
A isInvalidWithNonOgoneUrl() 0 6 1
A isValidWithOgoneUrl() 0 6 1
A isValidWhenAliasSet() 0 8 1
A IsInvalidWithTooLongAlias() 8 8 1
A isValidWhenOperationIsSet() 0 6 1
A BadParametersCauseExceptions() 0 5 1
A provideBadParameters() 0 7 1
A provideMinimalDirectLinkPaymentRequest() 0 12 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
 * This file is part of the Marlon Ogone package.
4
 *
5
 * (c) Marlon BVBA <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Ogone\Tests\DirectLink;
12
13
use Ogone\DirectLink\PaymentOperation;
14
use Ogone\Tests;
15
use Ogone\Tests\ShaComposer\FakeShaComposer;
16
use Ogone\DirectLink\DirectLinkPaymentRequest;
17
use Ogone\DirectLink\Alias;
18
19
class DirectLinkPaymentRequestTest extends \PHPUnit_Framework_TestCase
20
{
21
22
    /** @test */
23
    public function IsValidWhenRequiredFieldsAreFilledIn()
24
    {
25
        $directLinkPaymentRequest = $this->provideMinimalDirectLinkPaymentRequest();
26
        $directLinkPaymentRequest->validate();
27
    }
28
29
    /**
30
     * @test
31
     * @expectedException \RuntimeException
32
     */
33
    public function IsInvalidWhenFieldsAreMissing()
34
    {
35
        $directLinkPaymentRequest = new DirectLinkPaymentRequest(new FakeShaComposer);
36
        $directLinkPaymentRequest->validate();
37
    }
38
39
    /**
40
     * @test
41
     * @expectedException \InvalidArgumentException
42
     */
43
    public function isInvalidWithNonOgoneUrl()
44
    {
45
        $directLinkPaymentRequest = $this->provideMinimalDirectLinkPaymentRequest();
46
        $directLinkPaymentRequest->setOgoneUri('http://example.com');
47
        $directLinkPaymentRequest->validate();
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function isValidWithOgoneUrl()
54
    {
55
        $directLinkPaymentRequest = $this->provideMinimalDirectLinkPaymentRequest();
56
        $directLinkPaymentRequest->setOgoneUri(DirectLinkPaymentRequest::PRODUCTION);
57
        $directLinkPaymentRequest->validate();
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function isValidWhenAliasSet()
64
    {
65
        $alias = new Alias('customer_123');
66
67
        $directLinkPaymentRequest = $this->provideMinimalDirectLinkPaymentRequest();
68
        $directLinkPaymentRequest->setAlias($alias);
69
        $directLinkPaymentRequest->validate();
70
    }
71
72
    /**
73
     * @test
74
     * @expectedException \InvalidArgumentException
75
     */
76 View Code Duplication
    public function IsInvalidWithTooLongAlias()
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...
77
    {
78
        $alias = new Alias(str_repeat('repeat', 10));
79
80
        $directLinkPaymentRequest = $this->provideMinimalDirectLinkPaymentRequest();
81
        $directLinkPaymentRequest->setAlias($alias);
82
        $directLinkPaymentRequest->validate();
83
    }
84
85
    /**
86
     * @test
87
     */
88
    public function isValidWhenOperationIsSet()
89
    {
90
        $directLinkPaymentRequest = $this->provideMinimalDirectLinkPaymentRequest();
91
        $directLinkPaymentRequest->setOperation(new PaymentOperation(PaymentOperation::REQUEST_FOR_DIRECT_SALE));
92
        $directLinkPaymentRequest->validate();
93
    }
94
95
    /**
96
     * @test
97
     * @dataProvider provideBadParameters
98
     * @expectedException \InvalidArgumentException
99
     */
100
    public function BadParametersCauseExceptions($method, $value)
101
    {
102
        $directLinkPaymentRequest = new DirectLinkPaymentRequest(new FakeShaComposer);
103
        $directLinkPaymentRequest->$method($value);
104
    }
105
106
    public function provideBadParameters()
107
    {
108
        return array(
109
            array('setPswd', '12'),
110
            array('setUserid', '1'),
111
        );
112
    }
113
114
    /** @return DirectLinkPaymentRequest */
115
    private function provideMinimalDirectLinkPaymentRequest()
116
    {
117
        $directLinkRequest = new DirectLinkPaymentRequest(new FakeShaComposer());
118
        $directLinkRequest->setPspid('123456');
119
        $directLinkRequest->setUserId('user_1234');
120
        $directLinkRequest->setPassword('abracadabra');
121
        $directLinkRequest->setAmount(100);
122
        $directLinkRequest->setCurrency('EUR');
123
        $directLinkRequest->setOrderid('999');
124
125
        return $directLinkRequest;
126
    }
127
}
128