Completed
Push — master ( 314e2a...089e57 )
by mw
84:04 queued 49:07
created

TitleMoveComplete::process()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 47
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 20
nc 2
nop 0
dl 0
loc 47
ccs 16
cts 16
cp 1
crap 3
rs 9.0303
c 1
b 0
f 0
1
<?php
2
3
namespace SMW\MediaWiki\Hooks;
4
5
use SMW\ApplicationFactory;
6
use SMW\Factbox\FactboxCache;
7
use SMW\EventHandler;
8
9
/**
10
 * TitleMoveComplete occurs whenever a request to move an article
11
 * is completed
12
 *
13
 * This method will be called whenever an article is moved so that
14
 * semantic properties are moved accordingly.
15
 *
16
 * @see http://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete
17
 *
18
 * @license GNU GPL v2+
19
 * @since 1.9
20
 *
21
 * @author mwjames
22
 */
23
class TitleMoveComplete {
24
25
	/**
26
	 * @var Title
27
	 */
28
	protected $oldTitle = null;
29
30
	/**
31
	 * @var Title
32
	 */
33
	protected $newTitle = null;
34
35
	/**
36
	 * @var User
37
	 */
38
	protected $user = null;
39
40
	/**
41
	 * @var integer
42
	 */
43
	protected $oldId;
44
45
	/**
46
	 * @var integer
47
	 */
48
	protected $newId;
49
50
	/**
51
	 * @since  1.9
52
	 *
53
	 * @param Title $oldTitle old title
54
	 * @param Title $newTitle: new title
0 ignored issues
show
Documentation introduced by
There is no parameter named $newTitle:. Did you maybe mean $newTitle?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
55
	 * @param Use $user user who did the move
56
	 * @param $oldId database ID of the page that's been moved
57
	 * @param $newId database ID of the created redirect
58
	 */
59 10
	public function __construct( &$oldTitle, &$newTitle, &$user, $oldId, $newId ) {
60 10
		$this->oldTitle = $oldTitle;
61 10
		$this->newTitle = $newTitle;
62 10
		$this->user = $user;
0 ignored issues
show
Documentation Bug introduced by
It seems like $user of type object<SMW\MediaWiki\Hooks\Use> is incompatible with the declared type object<SMW\MediaWiki\Hooks\User> of property $user.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
63 10
		$this->oldId = $oldId;
64 10
		$this->newId = $newId;
65 10
	}
66
67
	/**
68
	 * @since 1.9
69
	 *
70
	 * @return true
71
	 */
72 9
	public function process() {
73
74 9
		$applicationFactory = ApplicationFactory::getInstance();
75
76
		// Delete all data for a non-enabled target NS
77 9
		if ( !$applicationFactory->getNamespaceExaminer()->isSemanticEnabled( $this->newTitle->getNamespace() ) || $this->newId == 0 ) {
78
79 4
			$applicationFactory->getStore()->deleteSubject(
80 4
				$this->oldTitle
81
			);
82
83
		} else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
84
85
		// Using a different approach since the hook is not triggered
86
		// by #REDIRECT which can cause inconsistencies
87
		// @see 2.3 / StoreUpdater
88
89
		//	$applicationFactory->getStore()->changeTitle(
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
90
		//		$this->oldTitle,
91
		//		$this->newTitle,
92
		//		$this->oldId,
93
		//		$this->newId
94
		//	);
95
		}
96
97 9
		$eventHandler = EventHandler::getInstance();
98
99 9
		$dispatchContext = $eventHandler->newDispatchContext();
100 9
		$dispatchContext->set( 'title', $this->oldTitle );
101
		$dispatchContext->set( 'context', 'ArticleMove' );
102 9
103 9
		$eventHandler->getEventDispatcher()->dispatch(
104
			'cached.prefetcher.reset',
105
			$dispatchContext
106
		);
107 9
108 9
		$dispatchContext = $eventHandler->newDispatchContext();
109 9
		$dispatchContext->set( 'title', $this->newTitle );
110
		$dispatchContext->set( 'context', 'ArticleMove' );
111 9
112 9
		$eventHandler->getEventDispatcher()->dispatch(
113
			'cached.prefetcher.reset',
114
			$dispatchContext
115
		);
116 9
117
		return true;
118
	}
119
120
}
121