EmailTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 123
Duplicated Lines 19.51 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 24
loc 123
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 1

13 Methods

Rating   Name   Duplication   Size   Complexity  
A testNewInstance() 0 10 1
A testNewInstance1() 8 8 1
A testNewInstance2() 8 8 1
A testNewInstance3() 8 8 1
A testNewInstance4() 0 4 1
A testParse1() 0 8 1
A testParse2() 0 5 1
A providerForParse() 0 17 1
A providerForParse2() 0 7 1
A testParseWithProvider() 0 5 1
A testParseWithProvider2() 0 5 1
A testParse5() 0 4 1
A testParse6() 0 4 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
namespace MailSoTests;
4
5
class EmailTest extends \PHPUnit_Framework_TestCase
6
{
7
	public function testNewInstance()
8
	{
9
		$oMail = \MailSo\Mime\Email::NewInstance('[email protected]', 'Administrator');
10
		$this->assertEquals('[email protected]', $oMail->GetEmail());
11
		$this->assertEquals('Administrator', $oMail->GetDisplayName());
12
		$this->assertEquals('admin', $oMail->GetAccountName());
13
		$this->assertEquals('example.com', $oMail->GetDomain());
14
		$this->assertEquals('"Administrator" <[email protected]>', $oMail->ToString());
15
		$this->assertEquals(array('Administrator', '[email protected]', 'none', ''), $oMail->ToArray());
16
	}
17
18 View Code Duplication
	public function testNewInstance1()
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...
19
	{
20
		$oMail = \MailSo\Mime\Email::NewInstance('[email protected]');
21
		$this->assertEquals('[email protected]', $oMail->GetEmail());
22
		$this->assertEquals('', $oMail->GetDisplayName());
23
		$this->assertEquals('[email protected]', $oMail->ToString());
24
		$this->assertEquals(array('', '[email protected]', 'none', ''), $oMail->ToArray());
25
	}
26
27 View Code Duplication
	public function testNewInstance2()
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
		$oMail = \MailSo\Mime\Email::NewInstance('[email protected]', 'Administrator');
30
		$this->assertEquals('[email protected]', $oMail->GetEmail());
31
		$this->assertEquals('Administrator', $oMail->GetDisplayName());
32
		$this->assertEquals('"Administrator" <[email protected]>', $oMail->ToString());
33
		$this->assertEquals(array('Administrator', '[email protected]', 'none', ''), $oMail->ToArray());
34
	}
35
36 View Code Duplication
	public function testNewInstance3()
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...
37
	{
38
		$oMail = \MailSo\Mime\Email::NewInstance('[email protected]', '');
39
		$this->assertEquals('[email protected]', $oMail->GetEmail());
40
		$this->assertEquals('', $oMail->GetDisplayName());
41
		$this->assertEquals('[email protected]', $oMail->ToString());
42
		$this->assertEquals(array('', '[email protected]', 'none', ''), $oMail->ToArray());
43
	}
44
45
	/**
46
	 * @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
47
	 */
48
	public function testNewInstance4()
49
	{
50
		$oMail = \MailSo\Mime\Email::NewInstance('');
0 ignored issues
show
Unused Code introduced by
$oMail is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
51
	}
52
53
	public function testParse1()
54
	{
55
		$oMail = \MailSo\Mime\Email::Parse('[email protected]');
56
		$this->assertEquals('[email protected]', $oMail->GetEmail());
57
58
		$oMail = \MailSo\Mime\Email::Parse('<[email protected]>');
59
		$this->assertEquals('[email protected]', $oMail->GetEmail());
60
	}
61
62
	public function testParse2()
63
	{
64
		$oMail = \MailSo\Mime\Email::Parse('"Тест" <[email protected]>');
65
		$this->assertEquals('"Тест" <[email protected]>', $oMail->ToString());
66
	}
67
68
	public static function providerForParse()
69
	{
70
		return array(
71
			array('test <[email protected]>',
72
				array('test', '[email protected]')),
73
			array('test<[email protected]>',
74
				array('test', '[email protected]')),
75
			array('test< [email protected] >',
76
				array('test', '[email protected]')),
77
			array('"New \" Admin" <[email protected]>',
78
				array('New " Admin', '[email protected]')),
79
			array('"Тест" <[email protected]>',
80
				array('Тест', '[email protected]')),
81
			array('Microsoft Outlook<[email protected]>',
82
				array('Microsoft Outlook', '[email protected]')),
83
		);
84
	}
85
86
	public static function providerForParse2()
87
	{
88
		return array(
89
			array('[email protected]',
90
				array('', 'help@президент.рф')),
91
		);
92
	}
93
94
	/**
95
     * @dataProvider providerForParse
96
     */
97
	public function testParseWithProvider($sValue, $aResult)
98
	{
99
		$oMail = \MailSo\Mime\Email::Parse($sValue);
100
		$this->assertEquals($aResult, $oMail->ToArray(false, false));
101
	}
102
103
	/**
104
     * @dataProvider providerForParse2
105
     */
106
	public function testParseWithProvider2($sValue, $aResult)
107
	{
108
		$oMail = \MailSo\Mime\Email::Parse($sValue);
109
		$this->assertEquals($aResult, $oMail->ToArray(true, false));
110
	}
111
112
	/**
113
	 * @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
114
	 */
115
	public function testParse5()
116
	{
117
		\MailSo\Mime\Email::Parse('');
118
	}
119
120
	/**
121
	 * @expectedException \MailSo\Base\Exceptions\InvalidArgumentException
122
	 */
123
	public function testParse6()
124
	{
125
		\MailSo\Mime\Email::Parse('example.com');
126
	}
127
}
128