Completed
Push — master ( c7064c...56da7b )
by mw
9s
created

AppFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 82
rs 10
ccs 23
cts 23
cp 1
wmc 7
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A newDatabaseConnection() 0 3 1
A newUserFromTitle() 0 3 1
A newShortUrlAnnotator() 0 7 1
A newExifDataAnnotator() 0 3 1
A newWikiPage() 0 15 2
1
<?php
2
3
namespace SESP;
4
5
use SESP\Annotator\ShortUrlAnnotator;
6
use SESP\Annotator\ExifDataAnnotator;
7
use SMW\SemanticData;
8
use File;
9
use Title;
10
11
/**
12
 * @license GNU GPL v2+
13
 * @since 1.3
14
 *
15
 * @author mwjames
16
 */
17
class AppFactory {
18
19
	/**
20
	 * @var string
21
	 */
22
	private $shortUrlPrefix;
23
24 7
	public function __construct( $shortUrlPrefix = '' ) {
25 7
		$this->shortUrlPrefix = $shortUrlPrefix;
26 7
	}
27
28
	/**
29
	 * @since 1.3
30
	 *
31
	 * @return DatabaseBase
32
	 */
33 1
	public function newDatabaseConnection() {
34 1
		return wfGetDB( DB_SLAVE );
35
	}
36
37
	/**
38
	 * @since 1.3
39
	 *
40
	 * @param Title $title
41
	 *
42
	 * @return WikiPage
43
	 */
44 2
	public function newWikiPage( Title $title ) {
45
46
		// #55
47
		// Fight a possible DB corruption and avoid "NS_MEDIA is a virtual namespace; use NS_FILE"
48 2
		if ( $title->getNamespace() === NS_MEDIA ) {
49 1
			$title = Title::makeTitleSafe(
50 1
				NS_FILE,
51 1
				$title->getDBkey(),
52 1
				$title->getInterwiki(),
53 1
				$title->getFragment()
54 1
			);
55 1
		}
56
57 2
		return \WikiPage::factory( $title );
58
	}
59
60
	/**
61
	 * @since 1.3
62
	 *
63
	 * @param Title $title
64
	 *
65
	 * @return User
66
	 */
67 1
	public function newUserFromTitle( Title $title ) {
68 1
		return \User::newFromName( $title->getText() );
69
	}
70
71
	/**
72
	 * @since 1.3
73
	 *
74
	 * @param SemanticData $semanticData
75
	 *
76
	 * @return ShortUrlAnnotator
77
	 */
78 1
	public function newShortUrlAnnotator( SemanticData $semanticData ) {
79
80 1
		$shortUrlAnnotator = new ShortUrlAnnotator( $semanticData );
81 1
		$shortUrlAnnotator->setShortUrlPrefix( $this->shortUrlPrefix );
82
83 1
		return $shortUrlAnnotator;
84
	}
85
86
	/**
87
	 * @since 1.3
88
	 *
89
	 * @param SemanticData $semanticData
90
	 * @param File $file
91
	 *
92
	 * @return ExifDataAnnotator
93
	 */
94 1
	public function newExifDataAnnotator( SemanticData $semanticData, File $file ) {
95 1
		return new ExifDataAnnotator( $semanticData, $file );
96
	}
97
98
}
99