RaggettInternalPHP::cleanWrapped()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 21
nc 5
nop 3
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace MediaWiki\Tidy;
4
5
class RaggettInternalPHP extends RaggettBase {
6
	/**
7
	 * Use the HTML tidy extension to use the tidy library in-process,
8
	 * saving the overhead of spawning a new process.
9
	 *
10
	 * @param string $text HTML to check
11
	 * @param bool $stderr Whether to read result from error status instead of output
12
	 * @param int &$retval Exit code (-1 on internal error)
13
	 * @return string|null
14
	 */
15
	protected function cleanWrapped( $text, $stderr = false, &$retval = null ) {
16
		if ( !class_exists( 'tidy' ) ) {
17
			wfWarn( "Unable to load internal tidy class." );
18
			$retval = -1;
19
20
			return null;
21
		}
22
23
		$tidy = new \tidy;
24
		$tidy->parseString( $text, $this->config['tidyConfigFile'], 'utf8' );
25
26
		if ( $stderr ) {
27
			$retval = $tidy->getStatus();
28
			return $tidy->errorBuffer;
0 ignored issues
show
Bug introduced by
The property errorBuffer does not seem to exist in tidy.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29
		}
30
31
		$tidy->cleanRepair();
32
		$retval = $tidy->getStatus();
33
		if ( $retval == 2 ) {
34
			// 2 is magic number for fatal error
35
			// https://secure.php.net/manual/en/tidy.getstatus.php
36
			$cleansource = null;
37
		} else {
38
			$cleansource = tidy_get_output( $tidy );
39
			if ( !empty( $this->config['debugComment'] ) && $retval > 0 ) {
40
				$cleansource .= "<!--\nTidy reports:\n" .
41
					str_replace( '-->', '--&gt;', $tidy->errorBuffer ) .
42
					"\n-->";
43
			}
44
		}
45
46
		return $cleansource;
47
	}
48
49
	public function supportsValidate() {
50
		return true;
51
	}
52
}
53