Completed
Push — master ( 314506...335380 )
by mw
100:54 queued 62:54
created

PageRefresher::doRefreshPoolOfPages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Tests\Utils;
4
5
use RuntimeException;
6
use SMW\ApplicationFactory;
7
use SMW\ContentParser;
8
use SMW\DIWikiPage;
9
use SMW\MediaWiki\Jobs\UpdateJob;
10
use SMW\Store;
11
use Title;
12
use WikiPage;
13
14
/**
15
 *
16
 * @group SMW
17
 * @group SMWExtension
18
 *
19
 * @license GNU GPL v2+
20
 * @since 2.0
21
 */
22
class PageRefresher {
23
24
	/**
25
	 * @since 2.0
26
	 *
27
	 * @param mixed $title
28
	 *
29
	 * @return PageRefresher
30
	 */
31
	public function doRefresh( $title ) {
32
33
		if ( $title instanceof WikiPage || $title instanceof DIWikiPage ) {
0 ignored issues
show
Bug introduced by
The class WikiPage 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...
34
			$title = $title->getTitle();
35
		}
36
37
		if ( !$title instanceof Title ) {
0 ignored issues
show
Bug introduced by
The class Title 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...
38
			throw new RuntimeException( 'Expected a title instance' );
39
		}
40
41
		$contentParser = new ContentParser( $title );
42
		$contentParser->forceToUseParser();
43
44
		$parserData = ApplicationFactory::getInstance()->newParserData(
45
			$title,
46
			$contentParser->parse()->getOutput()
0 ignored issues
show
Bug introduced by
It seems like $contentParser->parse()->getOutput() targeting SMW\ContentParser::getOutput() can also be of type null; however, SMW\ApplicationFactory::newParserData() does only seem to accept object<ParserOutput>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
47
		);
48
49
		$parserData->updateStore();
50
51
		return $this;
52
	}
53
54
	/**
55
	 * @since 2.1
56
	 *
57
	 * @param array $pages
58
	 *
59
	 * @return PageRefresher
60
	 */
61
	public function doRefreshPoolOfPages( array $pages ) {
62
		foreach ( $pages as $page ) {
63
			$this->doRefreshByUpdateJob( $page );
64
		}
65
	}
66
67
	/**
68
	 * @since 2.1
69
	 *
70
	 * @param mixed $title
71
	 *
72
	 * @return PageRefresher
73
	 */
74
	public function doRefreshByUpdateJob( $title ) {
75
76
		if ( $title instanceof WikiPage || $title instanceof DIWikiPage ) {
0 ignored issues
show
Bug introduced by
The class WikiPage 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...
77
			$title = $title->getTitle();
78
		}
79
80
		if ( is_string( $title ) ) {
81
			$title = Title::newFromText( $title );
82
		}
83
84
		if ( !$title instanceof Title ) {
0 ignored issues
show
Bug introduced by
The class Title 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...
85
			throw new RuntimeException( 'Expected a title instance' );
86
		}
87
88
		$job = new UpdateJob( $title );
89
		$job->run();
90
91
		return $this;
92
	}
93
94
}
95