Completed
Push — master ( b59c0c...c68fa7 )
by Josef
08:24
created

ValidatorTest   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 158
Duplicated Lines 91.14 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 1
Metric Value
dl 144
loc 158
rs 10
c 4
b 1
f 1
wmc 23
lcom 1
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testCheckCartItemName() 20 20 3
A testCheckCartItemDescription() 12 12 2
A testCheckCartItemQuantity() 12 12 2
A testCheckOrderId() 20 20 3
A testCheckReturnUrl() 12 12 2
A testDescription() 12 12 2
A testMerchantData() 12 12 2
A testCustomerId() 12 12 2
A testPayId() 12 12 2
A testTtlSec() 20 20 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 declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway;
4
5
class ValidatorTest extends \PHPUnit_Framework_TestCase
6
{
7
8 View Code Duplication
	public function testCheckCartItemName()
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...
9
	{
10
		Validator::checkCartItemName('foo name');
11
12
		try {
13
			Validator::checkCartItemName('very long long long cart item name');
14
			$this->fail();
15
16
		} catch (\InvalidArgumentException $e) {
17
			$this->assertSame('Cart item name can have maximum of 20 characters.', $e->getMessage());
18
		}
19
20
		try {
21
			Validator::checkCartItemName(' whitespace');
22
			$this->fail();
23
24
		} catch (\InvalidArgumentException $e) {
25
			$this->assertSame('Argument starts or ends with whitespace.', $e->getMessage());
26
		}
27
	}
28
29 View Code Duplication
	public function testCheckCartItemDescription()
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...
30
	{
31
		Validator::checkCartItemDescription('foo description');
32
33
		try {
34
			Validator::checkCartItemDescription('very long long long cart item description');
35
			$this->fail();
36
37
		} catch (\InvalidArgumentException $e) {
38
			$this->assertSame('Cart item description can have maximum of 40 characters.', $e->getMessage());
39
		}
40
	}
41
42 View Code Duplication
	public function testCheckCartItemQuantity()
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...
43
	{
44
		Validator::checkCartItemQuantity(2);
45
46
		try {
47
			Validator::checkCartItemQuantity(0);
48
			$this->fail();
49
50
		} catch (\InvalidArgumentException $e) {
51
			$this->assertSame('Quantity must be greater than 0. 0 given.', $e->getMessage());
52
		}
53
	}
54
55 View Code Duplication
	public function testCheckOrderId()
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...
56
	{
57
		Validator::checkOrderId('123');
58
59
		try {
60
			Validator::checkOrderId('123456789123456789');
61
			$this->fail();
62
63
		} catch (\InvalidArgumentException $e) {
64
			$this->assertSame('OrderId can have maximum of 10 characters.', $e->getMessage());
65
		}
66
67
		try {
68
			Validator::checkOrderId('abc');
69
			$this->fail();
70
71
		} catch (\InvalidArgumentException $e) {
72
			$this->assertSame('OrderId must be numeric value. abc given.', $e->getMessage());
73
		}
74
	}
75
76 View Code Duplication
	public function testCheckReturnUrl()
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
		Validator::checkReturnUrl('https://example.com');
79
80
		try {
81
			Validator::checkReturnUrl('https://example.com/' . implode('-', array_fill(0, 100, 'long')));
82
			$this->fail();
83
84
		} catch (\InvalidArgumentException $e) {
85
			$this->assertSame('ReturnUrl can have maximum of 300 characters.', $e->getMessage());
86
		}
87
	}
88
89 View Code Duplication
	public function testDescription()
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
		Validator::checkDescription('foo description');
92
93
		try {
94
			Validator::checkDescription(implode(' ', array_fill(0, 60, 'very')) . ' long description');
95
			$this->fail();
96
97
		} catch (\InvalidArgumentException $e) {
98
			$this->assertSame('Description can have maximum of 255 characters.', $e->getMessage());
99
		}
100
	}
101
102 View Code Duplication
	public function testMerchantData()
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...
103
	{
104
		Validator::checkMerchantData('foo merchant data');
105
106
		try {
107
			Validator::checkMerchantData(implode(' ', array_fill(0, 60, 'very')) . ' long merchantData');
108
			$this->fail();
109
110
		} catch (\InvalidArgumentException $e) {
111
			$this->assertSame('MerchantData can have maximum of 255 characters in encoded state.', $e->getMessage());
112
		}
113
	}
114
115 View Code Duplication
	public function testCustomerId()
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...
116
	{
117
		Validator::checkCustomerId('foo customerId');
118
119
		try {
120
			Validator::checkCustomerId('very very very very very very very very long long long customerId');
121
			$this->fail();
122
123
		} catch (\InvalidArgumentException $e) {
124
			$this->assertSame('CustomerId can have maximum of 50 characters.', $e->getMessage());
125
		}
126
	}
127
128 View Code Duplication
	public function testPayId()
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...
129
	{
130
		Validator::checkPayId('foo payId');
131
132
		try {
133
			Validator::checkPayId('very long long payId');
134
			$this->fail();
135
136
		} catch (\InvalidArgumentException $e) {
137
			$this->assertSame('PayId can have maximum of 15 characters.', $e->getMessage());
138
		}
139
	}
140
141 View Code Duplication
	public function testTtlSec()
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...
142
	{
143
		Validator::checkTtlSec(500);
144
145
		try {
146
			Validator::checkTtlSec(200);
147
			$this->fail();
148
149
		} catch (\InvalidArgumentException $e) {
150
			$this->assertSame('TTL sec is out of range (300 - 1800). Current value is 200.', $e->getMessage());
151
		}
152
153
		try {
154
			Validator::checkTtlSec(3000);
155
			$this->fail();
156
157
		} catch (\InvalidArgumentException $e) {
158
			$this->assertSame('TTL sec is out of range (300 - 1800). Current value is 3000.', $e->getMessage());
159
		}
160
	}
161
162
}
163