Completed
Push — master ( 274d0e...9fc64f )
by mw
34:08
created

registerCallbackHandlers()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 99
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 99
ccs 43
cts 45
cp 0.9556
rs 8.3103
c 1
b 0
f 1
cc 1
eloc 49
nc 1
nop 1
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SMW;
4
5
use Onoi\CallbackContainer\CallbackContainer;
6
use Onoi\CallbackContainer\CallbackLoader;
7
8
use SMW\MediaWiki\PageCreator;
9
use SMW\MediaWiki\TitleCreator;
10
use SMW\MediaWiki\Jobs\JobFactory;
11
use SMW\Factbox\FactboxFactory;
12
use Closure;
13
14
/**
15
 * @license GNU GPL v2+
16
 * @since 2.3
17
 *
18
 * @author mwjames
19
 */
20
class SharedCallbackContainer implements CallbackContainer {
21
22 233
	public function register( CallbackLoader $callbackLoader ) {
23 233
		$this->registerCallbackHandlers( $callbackLoader );
24 233
	}
25
26 233
	private function registerCallbackHandlers( $callbackLoader ) {
27
28 233
		$callbackLoader->registerExpectedReturnType( 'Settings', '\SMW\Settings' );
29
30
		$callbackLoader->registerCallback( 'Settings', function() use ( $callbackLoader )  {
31 232
			return Settings::newFromGlobals();
32 233
		} );
33
34 233
		$callbackLoader->registerExpectedReturnType( 'Store', '\SMW\Store' );
35
36
		$callbackLoader->registerCallback( 'Store', function() use ( $callbackLoader ) {
37 226
			return StoreFactory::getStore( $callbackLoader->singleton( 'Settings' )->get( 'smwgDefaultStore' ) );
38 233
		} );
39
40 233
		$callbackLoader->registerExpectedReturnType( 'CacheFactory', '\SMW\CacheFactory' );
41
42 233
		$callbackLoader->registerCallback( 'CacheFactory', function() {
43 1
			return new CacheFactory();
44 233
		} );
45
46
		$callbackLoader->registerExpectedReturnType( 'Cache', '\Onoi\Cache\Cache' );
47 140
48 233
		$callbackLoader->registerCallback( 'Cache', function() use ( $callbackLoader ) {
49
			return $callbackLoader->load( 'CacheFactory' )->newMediaWikiCompositeCache();
50 233
		} );
51
52 233
		$callbackLoader->registerCallback( 'NamespaceExaminer', function() use ( $callbackLoader ) {
53 155
			return NamespaceExaminer::newFromArray( $callbackLoader->singleton( 'Settings' )->get( 'smwgNamespacesWithSemanticLinks' ) );
54 233
		} );
55
56 233
		$callbackLoader->registerExpectedReturnType( 'ParserData', '\SMW\ParserData' );
57
58 233
		$callbackLoader->registerCallback( 'ParserData', function( \Title $title, \ParserOutput $parserOutput ) {
59
			return new ParserData( $title, $parserOutput );
60 233
		} );
61
62 233
		$callbackLoader->registerCallback( 'MessageFormatter', function( \Language $language ) {
63 143
			return new MessageFormatter( $language );
64 233
		} );
65
66 233
		$callbackLoader->registerExpectedReturnType( 'PageCreator', '\SMW\MediaWiki\PageCreator' );
67
68 233
		$callbackLoader->registerCallback( 'PageCreator', function() {
69 5
			return new PageCreator();
70 233
		} );
71
72 233
		$callbackLoader->registerExpectedReturnType( 'TitleCreator', '\SMW\MediaWiki\TitleCreator' );
73
74 233
		$callbackLoader->registerCallback( 'TitleCreator', function() {
75
			return new TitleCreator();
76 233
		} );
77
78 233
		$callbackLoader->registerExpectedReturnType( 'WikiPage', '\WikiPage' );
79
80 233
		$callbackLoader->registerCallback( 'WikiPage', function( \Title $title ) {
81 29
			return \WikiPage::factory( $title );
82 233
		} );
83
84 233
		$callbackLoader->registerExpectedReturnType( 'ContentParser', '\SMW\ContentParser' );
85
86 233
		$callbackLoader->registerCallback( 'ContentParser', function( \Title $title ) {
87 128
			return new ContentParser( $title );
88 233
		} );
89
90 233
		$callbackLoader->registerExpectedReturnType( 'JobFactory', '\SMW\MediaWiki\Jobs\JobFactory' );
91
92 233
		$callbackLoader->registerCallback( 'JobFactory', function() {
93 3
			return new JobFactory();
94 233
		} );
95 233
96
		$callbackLoader->registerExpectedReturnType( 'FactboxFactory', '\SMW\Factbox\FactboxFactory' );
97
98
		$callbackLoader->registerCallback( 'FactboxFactory', function() {
99
			return new FactboxFactory();
100
		} );
101
102
		$callbackLoader->registerExpectedReturnType( 'PropertySpecificationLookup', '\SMW\PropertySpecificationLookup' );
103
104
		$callbackLoader->registerCallback( 'PropertySpecificationLookup', function() use ( $callbackLoader ) {
105
			$cacheFactory = $callbackLoader->load( 'CacheFactory' );
106
107
			$propertySpecificationLookup = new PropertySpecificationLookup(
108
				$callbackLoader->load( 'Store' ),
109
				$cacheFactory->newMediaWikiCompositeCache()
110
			);
111
112
			$propertySpecificationLookup->setCachePrefix(
113
				$cacheFactory->getCachePrefix()
114
			);
115
116
			// Uses the language object selected in user preferences. It is one
117
			// of two global language objects
118
			$propertySpecificationLookup->setLanguageCode(
119
				Localizer::getUserLanguage()->getCode()
120
			);
121
122
			return $propertySpecificationLookup;
123
		} );
124
	}
125
126
}
127