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.
Completed
Push — master ( e6da82...8fc91f )
by Emil
02:38
created

CEscaperTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 101
Duplicated Lines 62.38 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 1
dl 63
loc 101
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorSuccess() 0 8 1
A testSetAndGetEncoding() 0 13 1
A testEscapeHTML() 9 9 1
A testEscapeHTMLattr() 9 9 1
A testEscapeUrl() 9 9 1
A testEscapeCSS() 9 9 1
A testEscapeJs() 9 9 1
A testEscapeXML() 9 9 1
A testEscapeXmlattr() 9 9 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 112.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Scelus\Escaper;
4
5
/*
6
* All functions are based on the recommendations in the 
7
* XSS (Cross Site Scripting) Prevention Cheat Sheet:
8
* https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet
9
* 
10
*/
11
12
class CEscaperTest extends \PHPUnit_Framework_TestCase
13
{
14
	/**
15
     * Test 
16
     *
17
     * @return void
18
     *
19
     */
20
	public function testConstructorSuccess()
21
	{
22
		$el = new \Scelus\Escaper\CEscaper();
23
24
        $res = $el->getEncoding();
25
        $exp = 'UTF-8';
26
        $this->assertEquals($res, $exp, "Created element name missmatch.");
27
	}
28
	
29
	public function testSetAndGetEncoding()
30
	{
31
		$el = new \Scelus\Escaper\CEscaper('ASCII');
32
		
33
		$res = $el->getEncoding();
34
		$exp = 'ASCII';
35
		$this->assertEquals($res, $exp, "Created element argument missmatch");
36
		
37
		$el->setEncoding('UTF-8');
38
		$res = $el->getEncoding();
39
		$exp = 'UTF-8';
40
		$this->assertEquals($res, $exp, "setEncoding() produced missmatch");
41
	}
42
	
43 View Code Duplication
	public function testEscapeHTML()
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...
44
	{
45
		$el = new \Scelus\Escaper\CEscaper();
46
		
47
		$argument = '></div><h1>myattack</h1>';
48
		$res = $el->escapeHTML($argument);
49
		$exp = '&gt;&lt;&#x2F;div&gt;&lt;h1&gt;myattack&lt;&#x2F;h1&gt;';
50
		$this->assertEquals($res, $exp, "escapeHTML() produced missmatch");
51
	}
52
	
53 View Code Duplication
	public function testEscapeHTMLattr()
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
		$el = new \Scelus\Escaper\CEscaper();
56
		
57
		$argument = '"><h1>Hello</table';
58
		$res = $el->escapeHTMLattr($argument);
59
		$exp = "&#x22;&#x3e;&#x3c;h1&#x3e;Hello&#x3c;&#x2f;table";
60
		$this->assertEquals($res, $exp, "escapeHTMLattr() produced missmatch");
61
	}
62
	
63 View Code Duplication
	public function testEscapeUrl()
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...
64
	{
65
		$el = new \Scelus\Escaper\CEscaper();
66
		
67
		$argument = '"><script>alert(1)</script><a href="#';
68
		$res = $el->escapeUrl($argument);
69
		$exp = "%22%3E%3Cscript%3Ealert%281%29%3C%2Fscript%3E%3Ca%20href%3D%22%23";
70
		$this->assertEquals($res, $exp, "escapeUrl() produced missmatch");
71
	}
72
	
73 View Code Duplication
	public function testEscapeCSS()
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...
74
	{
75
		$el = new \Scelus\Escaper\CEscaper();
76
		
77
		$argument = '"><script>alert(1)</script><a href="#';
78
		$res = $el->escapeCSS($argument);
79
		$exp = '\22 \3e \3c script\3e alert\28 1\29 \3c \2f script\3e \3c a\20 href\3d \22 \23 ';
80
		$this->assertEquals($res, $exp, "escapeCSS() produced missmatch");
81
	}
82
	
83 View Code Duplication
	public function testEscapeJs()
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...
84
	{
85
		$el = new \Scelus\Escaper\CEscaper();
86
		
87
		$argument = "'; alert(100); var x='";
88
		$res = $el->escapeJs($argument);
89
		$exp = '\x27\x3b\x20alert\x28100\x29\x3b\x20var\x20x\x3d\x27';
90
		$this->assertEquals($res, $exp, "escapeJs() produced missmatch");
91
	}
92
	
93 View Code Duplication
		public function testEscapeXML()
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
		$el = new \Scelus\Escaper\CEscaper();
96
		
97
		$argument = '></div><h1>myattack</h1>';
98
		$res = $el->escapeXml($argument);
99
		$exp = '&gt;&lt;&#x2F;div&gt;&lt;h1&gt;myattack&lt;&#x2F;h1&gt;';
100
		$this->assertEquals($res, $exp, "escapeHTML() produced missmatch");
101
	}
102
	
103 View Code Duplication
	public function testEscapeXmlattr()
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...
104
	{
105
		$el = new \Scelus\Escaper\CEscaper();
106
		
107
		$argument = '"><h1>Hello</table';
108
		$res = $el->escapeXmlattr($argument);
109
		$exp = "&#x22;&#x3e;&#x3c;h1&#x3e;Hello&#x3c;&#x2f;table";
110
		$this->assertEquals($res, $exp, "escapeHTMLattr() produced missmatch");
111
	}
112
};