Completed
Pull Request — master (#3)
by Helpful
02:06
created
code/HTML5Value.php 3 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -2,34 +2,34 @@
 block discarded – undo
2 2
 
3 3
 class SS_HTML5Value extends SS_HTMLValue {
4 4
 
5
-	public function setContent($content) {
6
-		require_once(HTML5LIB_PATH.'/HTML5/Parser.php');
5
+    public function setContent($content) {
6
+        require_once(HTML5LIB_PATH.'/HTML5/Parser.php');
7 7
 
8
-		// Convert any errors to exceptions
9
-		set_error_handler(
10
-			function($no, $str){
11
-				throw new Exception("HTML Parse Error: ".$str);
12
-			},
13
-			error_reporting()
14
-		);
8
+        // Convert any errors to exceptions
9
+        set_error_handler(
10
+            function($no, $str){
11
+                throw new Exception("HTML Parse Error: ".$str);
12
+            },
13
+            error_reporting()
14
+        );
15 15
 
16
-		// Use HTML5lib to parse the HTML fragment
17
-		try {
18
-			$document = HTML5_Parser::parse(
19
-				'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'.
20
-				"<body>$content</body></html>"
21
-			);
22
-		}
23
-		catch (Exception $e) {
24
-			$document = false;
25
-		}
16
+        // Use HTML5lib to parse the HTML fragment
17
+        try {
18
+            $document = HTML5_Parser::parse(
19
+                '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'.
20
+                "<body>$content</body></html>"
21
+            );
22
+        }
23
+        catch (Exception $e) {
24
+            $document = false;
25
+        }
26 26
 
27
-		// Disable our error handler (restoring to previous value)
28
-		restore_error_handler();
27
+        // Disable our error handler (restoring to previous value)
28
+        restore_error_handler();
29 29
 
30
-		// If we couldn't parse the HTML, set the error state
31
-		if ($document) $this->setDocument($document);
32
-		else $this->setInvalid();
33
-	}
30
+        // If we couldn't parse the HTML, set the error state
31
+        if ($document) $this->setDocument($document);
32
+        else $this->setInvalid();
33
+    }
34 34
 
35 35
 }
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,12 +3,12 @@  discard block
 block discarded – undo
3 3
 class SS_HTML5Value extends SS_HTMLValue {
4 4
 
5 5
 	public function setContent($content) {
6
-		require_once(HTML5LIB_PATH.'/HTML5/Parser.php');
6
+		require_once(HTML5LIB_PATH . '/HTML5/Parser.php');
7 7
 
8 8
 		// Convert any errors to exceptions
9 9
 		set_error_handler(
10
-			function($no, $str){
11
-				throw new Exception("HTML Parse Error: ".$str);
10
+			function($no, $str) {
11
+				throw new Exception("HTML Parse Error: " . $str);
12 12
 			},
13 13
 			error_reporting()
14 14
 		);
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 		// Use HTML5lib to parse the HTML fragment
17 17
 		try {
18 18
 			$document = HTML5_Parser::parse(
19
-				'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'.
19
+				'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' .
20 20
 				"<body>$content</body></html>"
21 21
 			);
22 22
 		}
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,8 +19,7 @@  discard block
 block discarded – undo
19 19
 				'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'.
20 20
 				"<body>$content</body></html>"
21 21
 			);
22
-		}
23
-		catch (Exception $e) {
22
+		} catch (Exception $e) {
24 23
 			$document = false;
25 24
 		}
26 25
 
@@ -28,8 +27,11 @@  discard block
 block discarded – undo
28 27
 		restore_error_handler();
29 28
 
30 29
 		// If we couldn't parse the HTML, set the error state
31
-		if ($document) $this->setDocument($document);
32
-		else $this->setInvalid();
30
+		if ($document) {
31
+		    $this->setDocument($document);
32
+		} else {
33
+		    $this->setInvalid();
34
+		}
33 35
 	}
34 36
 
35 37
 }
36 38
\ No newline at end of file
Please login to merge, or discard this patch.
tests/HTML5ValueTest.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -4,62 +4,62 @@
 block discarded – undo
4 4
  * @subpackage tests
5 5
  */
6 6
 class SS_HTML5ValueTest extends SapphireTest {
7
-	public function testInvalidHTMLParsing() {
8
-		$value = new SS_HTML5Value();
7
+    public function testInvalidHTMLParsing() {
8
+        $value = new SS_HTML5Value();
9 9
 
10
-		$invalid = array (
11
-			'<p>Enclosed Value</p></p>'                              => '<p>Enclosed Value</p><p></p>',
12
-			'<meta content="text/html"></meta>'                      => '<meta content="text/html">',
13
-			'<p><div class="example"></div></p>'                     => '<p></p><div class="example"></div><p></p>'
14
-		);
10
+        $invalid = array (
11
+            '<p>Enclosed Value</p></p>'                              => '<p>Enclosed Value</p><p></p>',
12
+            '<meta content="text/html"></meta>'                      => '<meta content="text/html">',
13
+            '<p><div class="example"></div></p>'                     => '<p></p><div class="example"></div><p></p>'
14
+        );
15 15
 		
16
-		foreach($invalid as $input => $expected) {
17
-			$value->setContent($input);
18
-			$this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed');
19
-		}
20
-	}
16
+        foreach($invalid as $input => $expected) {
17
+            $value->setContent($input);
18
+            $this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed');
19
+        }
20
+    }
21 21
 
22
-	public function testUtf8Saving() {
23
-		$value = new SS_HTML5Value();
22
+    public function testUtf8Saving() {
23
+        $value = new SS_HTML5Value();
24 24
 
25
-		$value->setContent('<p>ö ß ā い 家</p>');
26
-		$this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent());
27
-	}
25
+        $value->setContent('<p>ö ß ā い 家</p>');
26
+        $this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent());
27
+    }
28 28
 
29
-	public function testWhitespaceHandling() {
30
-		$value = new SS_HTML5Value();
29
+    public function testWhitespaceHandling() {
30
+        $value = new SS_HTML5Value();
31 31
 
32
-		$value->setContent('<p></p> <p></p>');
33
-		$this->assertEquals('<p></p> <p></p>', $value->getContent());
34
-	}
32
+        $value->setContent('<p></p> <p></p>');
33
+        $this->assertEquals('<p></p> <p></p>', $value->getContent());
34
+    }
35 35
 
36
-	public function testInvalidHTMLTagNames() {
37
-		$value = new SS_HTML5Value();
36
+    public function testInvalidHTMLTagNames() {
37
+        $value = new SS_HTML5Value();
38 38
 
39
-		$invalid = array(
40
-			'<p><div><a href="test-link"></p></div>',
41
-			'<html><div><a href="test-link"></a></a></html_>'
42
-		);
39
+        $invalid = array(
40
+            '<p><div><a href="test-link"></p></div>',
41
+            '<html><div><a href="test-link"></a></a></html_>'
42
+        );
43 43
 		
44
-		foreach($invalid as $input) {
45
-			$value->setContent($input);
44
+        foreach($invalid as $input) {
45
+            $value->setContent($input);
46 46
 
47
-			$this->assertEquals(
48
-				'test-link',
49
-				$value->getElementsByTagName('a')->item(0)->getAttribute('href'),
50
-				'Link data can be extraced from malformed HTML'
51
-			);
52
-		}
53
-	}
47
+            $this->assertEquals(
48
+                'test-link',
49
+                $value->getElementsByTagName('a')->item(0)->getAttribute('href'),
50
+                'Link data can be extraced from malformed HTML'
51
+            );
52
+        }
53
+    }
54 54
 
55
-	public function testMixedNewlines() {
56
-		$value = new SS_HTML5Value();
55
+    public function testMixedNewlines() {
56
+        $value = new SS_HTML5Value();
57 57
 
58
-		$value->setContent("<p>paragraph</p>\n<ul><li>1</li>\r\n</ul>");
59
-		$this->assertEquals(
60
-			"<p>paragraph</p>\n<ul><li>1</li>\n</ul>",
61
-			$value->getContent(),
62
-			'Newlines get converted'
63
-		);
64
-	}
58
+        $value->setContent("<p>paragraph</p>\n<ul><li>1</li>\r\n</ul>");
59
+        $this->assertEquals(
60
+            "<p>paragraph</p>\n<ul><li>1</li>\n</ul>",
61
+            $value->getContent(),
62
+            'Newlines get converted'
63
+        );
64
+    }
65 65
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 	public function testInvalidHTMLParsing() {
8 8
 		$value = new SS_HTML5Value();
9 9
 
10
-		$invalid = array (
10
+		$invalid = array(
11 11
 			'<p>Enclosed Value</p></p>'                              => '<p>Enclosed Value</p><p></p>',
12 12
 			'<meta content="text/html"></meta>'                      => '<meta content="text/html">',
13 13
 			'<p><div class="example"></div></p>'                     => '<p></p><div class="example"></div><p></p>'
14 14
 		);
15 15
 		
16
-		foreach($invalid as $input => $expected) {
16
+		foreach ($invalid as $input => $expected) {
17 17
 			$value->setContent($input);
18 18
 			$this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed');
19 19
 		}
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			'<html><div><a href="test-link"></a></a></html_>'
42 42
 		);
43 43
 		
44
-		foreach($invalid as $input) {
44
+		foreach ($invalid as $input) {
45 45
 			$value->setContent($input);
46 46
 
47 47
 			$this->assertEquals(
Please login to merge, or discard this patch.