Completed
Push — master ( ad57d1...437e3d )
by mw
13s
created

SkinAfterContent::canPerformUpdate()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 7
c 2
b 0
f 0
nc 3
nop 0
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 5
rs 8.8571
1
<?php
2
3
namespace SMW\MediaWiki\Hooks;
4
5
use Skin;
6
use SMW\ApplicationFactory;
7
8
/**
9
 * SkinAfterContent hook to add text after the page content and
10
 * article metadata
11
 *
12
 * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinAfterContent
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.9
16
 *
17
 * @author mwjames
18
 */
19
class SkinAfterContent {
20
21
	/**
22
	 * @var string
23
	 */
24
	protected $data = null;
25
26
	/**
27
	 * @var Skin
28
	 */
29
	protected $skin = null;
30
31
	/**
32
	 * @since  1.9
33
	 *
34
	 * @param string $data
35
	 * @param Skin|null $skin
36
	 */
37 8
	public function __construct( &$data, Skin $skin = null ) {
38 8
		$this->data =& $data;
39 8
		$this->skin = $skin;
40 8
	}
41
42
	/**
43
	 * @since 1.9
44
	 *
45
	 * @return true
46
	 */
47 7
	public function process() {
48 7
		return $this->canPerformUpdate() ? $this->performUpdate() : true;
49
	}
50
51 7
	private function canPerformUpdate() {
52
53 7
		if ( !$this->skin instanceof Skin ) {
0 ignored issues
show
Bug introduced by
The class Skin does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
54 1
			return false;
55
		}
56
57 6
		$request = $this->skin->getContext()->getRequest();
58
59 6
		if ( $request->getVal( 'action' ) === 'delete' || $request->getVal( 'action' ) === 'purge' || !ApplicationFactory::getInstance()->getSettings()->get( 'smwgSemanticsEnabled' ) ) {
60 2
			return false;
61
		}
62
63 4
		return true;
64
	}
65
66 4
	private function performUpdate() {
67
68 4
		$cachedFactbox = ApplicationFactory::getInstance()->newFactboxFactory()->newCachedFactbox();
69
70 4
		$this->data .= $cachedFactbox->retrieveContent(
71 4
			$this->skin->getOutput()
72
		);
73
74 4
		return true;
75
	}
76
77
}
78