PageWatcher::watch()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 14
cp 0
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Mediawiki\DataModel\Page;
7
8
/**
9
 * @access private
10
 *
11
 * @author Addshore
12
 */
13
class PageWatcher extends Service {
14
15
	/**
16
	 * @param Page $page
17
	 *
18
	 * @return bool
19
	 */
20
	public function watch( Page $page ) {
21
		$params = [
22
			'token' => $this->api->getToken( 'watch' ),
23
		];
24
		if ( $page->getPageIdentifier()->getId() !== null ) {
25
			$params['pageids'] = $page->getPageIdentifier()->getId();
26
		} elseif ( $page->getPageIdentifier()->getTitle() !== null ) {
27
			$params['titles'] = $page->getPageIdentifier()->getTitle()->getTitle();
0 ignored issues
show
Deprecated Code introduced by
The method Mediawiki\DataModel\Title::getTitle() has been deprecated with message: in 0.6 use getText (makes things look cleaner)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
28
		} elseif ( $page->getRevisions()->getLatest() !== null ) {
29
			$params['revids'] = $page->getRevisions()->getLatest()->getId();
30
		}
31
32
		$this->api->postRequest( new SimpleRequest( 'watch', $params ) );
33
34
		return true;
35
	}
36
37
}
38