Test Failed
Push — master ( 3c6fc5...755ce0 )
by Rick
02:12
created

TypesTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 105
Duplicated Lines 80.95 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 2
dl 85
loc 105
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testInt() 12 12 1
A testString() 12 12 1
A testFloat() 12 12 1
A testBool() 13 13 1
A testArray() 12 12 1
A testCallable() 12 12 1
A testObject() 12 12 1
A testInstanceOf() 0 10 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
 * Copyright 2017 NanoSector
4
 *
5
 * You should have received a copy of the MIT license with the project.
6
 * See the LICENSE file for more information.
7
 */
8
9
use ValidationClosures\Types;
10
use PHPUnit\Framework\TestCase;
11
12
class TypesTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14 View Code Duplication
	public function testInt()
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...
15
	{
16
		$closure = Types::int();
17
18
		self::assertTrue($closure(10));
19
		self::assertFalse($closure('test'));
20
		self::assertFalse($closure(1.2));
21
		self::assertFalse($closure(false));
22
		self::assertFalse($closure([ ]));
23
		self::assertFalse($closure('in_array'));
24
		self::assertFalse($closure(new stdClass()));
25
	}
26
27 View Code Duplication
	public function testString()
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...
28
	{
29
		$closure = Types::string();
30
31
		self::assertFalse($closure(10));
32
		self::assertTrue($closure('test'));
33
		self::assertFalse($closure(1.2));
34
		self::assertFalse($closure(false));
35
		self::assertFalse($closure([ ]));
36
		self::assertTrue($closure('in_array'));
37
		self::assertFalse($closure(new stdClass()));
38
	}
39
40 View Code Duplication
	public function testFloat()
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...
41
	{
42
		$closure = Types::float();
43
44
		self::assertFalse($closure(10));
45
		self::assertFalse($closure('test'));
46
		self::assertTrue($closure(1.2));
47
		self::assertFalse($closure(false));
48
		self::assertFalse($closure([ ]));
49
		self::assertFalse($closure('in_array'));
50
		self::assertFalse($closure(new stdClass()));
51
	}
52
53 View Code Duplication
	public function testBool()
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...
54
	{
55
		$closure = Types::boolean();
56
57
		self::assertFalse($closure(10));
58
		self::assertFalse($closure('test'));
59
		self::assertFalse($closure(1.2));
60
		self::assertTrue($closure(false));
61
		self::assertTrue($closure(true));
62
		self::assertFalse($closure([ ]));
63
		self::assertFalse($closure('in_array'));
64
		self::assertFalse($closure(new stdClass()));
65
	}
66
67 View Code Duplication
	public function testArray()
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...
68
	{
69
		$closure = Types::array();
70
71
		self::assertFalse($closure(10));
72
		self::assertFalse($closure('test'));
73
		self::assertFalse($closure(1.2));
74
		self::assertFalse($closure(false));
75
		self::assertTrue($closure([ ]));
76
		self::assertFalse($closure('in_array'));
77
		self::assertFalse($closure(new stdClass()));
78
	}
79
80 View Code Duplication
	public function testCallable()
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...
81
	{
82
		$closure = Types::callable();
83
84
		self::assertFalse($closure(10));
85
		self::assertFalse($closure('test'));
86
		self::assertFalse($closure(1.2));
87
		self::assertFalse($closure(false));
88
		self::assertFalse($closure([ ]));
89
		self::assertTrue($closure('in_array'));
90
		self::assertFalse($closure(new stdClass()));
91
	}
92
93 View Code Duplication
	public function testObject()
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...
94
	{
95
		$closure = Types::object();
96
97
		self::assertFalse($closure(10));
98
		self::assertFalse($closure('test'));
99
		self::assertFalse($closure(1.2));
100
		self::assertFalse($closure(false));
101
		self::assertFalse($closure([ ]));
102
		self::assertFalse($closure('in_array'));
103
		self::assertTrue($closure(new stdClass()));
104
	}
105
106
	public function testInstanceOf()
107
	{
108
		$closure = Types::instanceof(Types::class);
109
110
		$stdClass = new stdClass();
111
		self::assertFalse($closure($stdClass));
112
113
		$types = new Types();
114
		self::assertTrue($closure($types));
115
	}
116
}
117