IntParamTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefinitions() 0 25 1
B valueProvider() 0 49 7
A getType() 0 3 1
1
<?php
2
3
namespace ParamProcessor\Tests\Integration\Definitions;
4
5
/**
6
 * @licence GNU GPL v2+
7
 * @author Jeroen De Dauw < [email protected] >
8
 */
9
class IntParamTest extends NumericParamTest {
10
11
	/**
12
	 * @see ParamDefinitionTest::getDefinitions
13
	 * @return array
14
	 */
15
	public function getDefinitions() {
16
		$params = parent::getDefinitions();
17
18
		$params['count'] = [
19
			'type' => 'integer',
20
		];
21
22
		$params['amount'] = [
23
			'type' => 'integer',
24
			'default' => 42,
25
			'upperbound' => 99,
26
		];
27
28
		$params['number'] = [
29
			'type' => 'integer',
30
			'upperbound' => 99,
31
		];
32
33
		$params['php-integer'] = [
34
			'type' => 'integer',
35
			'default' => 0,
36
		];
37
38
		return $params;
39
	}
40
41
	/**
42
	 * @see ParamDefinitionTest::valueProvider
43
	 *
44
	 * @param boolean $stringlyTyped
45
	 *
46
	 * @return array
47
	 */
48
	public function valueProvider( $stringlyTyped = true ) {
49
		$values = [
50
			'count' => [
51
				[ 42, true, 42 ],
52
				[ 'foo', false ],
53
				[ 4.2, false ],
54
				[ [ 42 ], false ],
55
			],
56
			'amount' => [
57
				[ 0, true, 0 ],
58
				[ 'foo', false, 42 ],
59
				[ 100, false, 42 ],
60
				[ 4.2, false, 42 ],
61
			],
62
			'number' => [
63
				[ 42, true, 42 ],
64
				[ 'foo', false ],
65
				[ 100, false ],
66
				[ 4.2, false ],
67
			],
68
			'empty' => [
69
				[ 42, true, 42 ],
70
				[ 4.2, false ],
71
				[ [ 42 ], false ],
72
			],
73
			'values' => [
74
				[ 1, true, 1 ],
75
				[ 'yes', false ],
76
				[ true, false ],
77
				[ 0.1, false ],
78
				[ [], false ],
79
			],
80
			'php-integer' => [
81
				[ 1337, !$stringlyTyped, 0 ],
82
			],
83
		];
84
85
		if ( $stringlyTyped ) {
86
			foreach ( $values as &$set ) {
87
				foreach ( $set as &$value ) {
88
					if ( $value[0] !== 1337 && ( is_float( $value[0] ) || is_int( $value[0] ) ) ) {
89
						$value[0] = (string)$value[0];
90
					}
91
				}
92
			}
93
		}
94
95
		return $values;
96
	}
97
98
	/**
99
	 * @see ParamDefinitionTest::getType
100
	 * @return string
101
	 */
102
	public function getType() {
103
		return 'integer';
104
	}
105
106
}
107