Conditions | 18 |
Paths | 440 |
Total Lines | 98 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | public static function applyDefaultConfig( array $lbConf, Config $mainConfig ) { |
||
38 | global $wgCommandLineMode; |
||
39 | |||
40 | $lbConf += [ |
||
41 | 'localDomain' => new DatabaseDomain( |
||
42 | $mainConfig->get( 'DBname' ), |
||
43 | null, |
||
44 | $mainConfig->get( 'DBprefix' ) |
||
45 | ), |
||
46 | 'profiler' => Profiler::instance(), |
||
47 | 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), |
||
48 | 'replLogger' => LoggerFactory::getInstance( 'DBReplication' ), |
||
49 | 'queryLogger' => LoggerFactory::getInstance( 'DBQuery' ), |
||
50 | 'connLogger' => LoggerFactory::getInstance( 'DBConnection' ), |
||
51 | 'perfLogger' => LoggerFactory::getInstance( 'DBPerformance' ), |
||
52 | 'errorLogger' => [ MWExceptionHandler::class, 'logException' ], |
||
53 | 'cliMode' => $wgCommandLineMode, |
||
54 | 'hostname' => wfHostname(), |
||
55 | // TODO: replace the global wfConfiguredReadOnlyReason() with a service. |
||
56 | 'readOnlyReason' => wfConfiguredReadOnlyReason(), |
||
57 | ]; |
||
58 | |||
59 | if ( $lbConf['class'] === 'LBFactorySimple' ) { |
||
60 | if ( isset( $lbConf['servers'] ) ) { |
||
|
|||
61 | // Server array is already explicitly configured; leave alone |
||
62 | } elseif ( is_array( $mainConfig->get( 'DBservers' ) ) ) { |
||
63 | foreach ( $mainConfig->get( 'DBservers' ) as $i => $server ) { |
||
64 | if ( $server['type'] === 'sqlite' ) { |
||
65 | $server += [ 'dbDirectory' => $mainConfig->get( 'SQLiteDataDir' ) ]; |
||
66 | } elseif ( $server['type'] === 'postgres' ) { |
||
67 | $server += [ |
||
68 | 'port' => $mainConfig->get( 'DBport' ), |
||
69 | // Work around the reserved word usage in MediaWiki schema |
||
70 | 'keywordTableMap' => [ 'user' => 'mwuser', 'text' => 'pagecontent' ] |
||
71 | ]; |
||
72 | } |
||
73 | $lbConf['servers'][$i] = $server + [ |
||
74 | 'schema' => $mainConfig->get( 'DBmwschema' ), |
||
75 | 'tablePrefix' => $mainConfig->get( 'DBprefix' ), |
||
76 | 'flags' => DBO_DEFAULT, |
||
77 | 'sqlMode' => $mainConfig->get( 'SQLMode' ), |
||
78 | 'utf8Mode' => $mainConfig->get( 'DBmysql5' ) |
||
79 | ]; |
||
80 | } |
||
81 | } else { |
||
82 | $flags = DBO_DEFAULT; |
||
83 | $flags |= $mainConfig->get( 'DebugDumpSql' ) ? DBO_DEBUG : 0; |
||
84 | $flags |= $mainConfig->get( 'DBssl' ) ? DBO_SSL : 0; |
||
85 | $flags |= $mainConfig->get( 'DBcompress' ) ? DBO_COMPRESS : 0; |
||
86 | $server = [ |
||
87 | 'host' => $mainConfig->get( 'DBserver' ), |
||
88 | 'user' => $mainConfig->get( 'DBuser' ), |
||
89 | 'password' => $mainConfig->get( 'DBpassword' ), |
||
90 | 'dbname' => $mainConfig->get( 'DBname' ), |
||
91 | 'schema' => $mainConfig->get( 'DBmwschema' ), |
||
92 | 'tablePrefix' => $mainConfig->get( 'DBprefix' ), |
||
93 | 'type' => $mainConfig->get( 'DBtype' ), |
||
94 | 'load' => 1, |
||
95 | 'flags' => $flags, |
||
96 | 'sqlMode' => $mainConfig->get( 'SQLMode' ), |
||
97 | 'utf8Mode' => $mainConfig->get( 'DBmysql5' ) |
||
98 | ]; |
||
99 | if ( $server['type'] === 'sqlite' ) { |
||
100 | $server[ 'dbDirectory'] = $mainConfig->get( 'SQLiteDataDir' ); |
||
101 | } elseif ( $server['type'] === 'postgres' ) { |
||
102 | $server['port'] = $mainConfig->get( 'DBport' ); |
||
103 | // Work around the reserved word usage in MediaWiki schema |
||
104 | $server['keywordTableMap'] = [ 'user' => 'mwuser', 'text' => 'pagecontent' ]; |
||
105 | } |
||
106 | $lbConf['servers'] = [ $server ]; |
||
107 | } |
||
108 | if ( !isset( $lbConf['externalClusters'] ) ) { |
||
109 | $lbConf['externalClusters'] = $mainConfig->get( 'ExternalServers' ); |
||
110 | } |
||
111 | } elseif ( $lbConf['class'] === 'LBFactoryMulti' ) { |
||
112 | if ( isset( $lbConf['serverTemplate'] ) ) { |
||
113 | $lbConf['serverTemplate']['schema'] = $mainConfig->get( 'DBmwschema' ); |
||
114 | $lbConf['serverTemplate']['sqlMode'] = $mainConfig->get( 'SQLMode' ); |
||
115 | $lbConf['serverTemplate']['utf8Mode'] = $mainConfig->get( 'DBmysql5' ); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804) |
||
120 | $sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); |
||
121 | if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) { |
||
122 | $lbConf['srvCache'] = $sCache; |
||
123 | } |
||
124 | $cCache = ObjectCache::getLocalClusterInstance(); |
||
125 | if ( $cCache->getQoS( $cCache::ATTR_EMULATION ) > $cCache::QOS_EMULATION_SQL ) { |
||
126 | $lbConf['memCache'] = $cCache; |
||
127 | } |
||
128 | $wCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
||
129 | if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) { |
||
130 | $lbConf['wanCache'] = $wCache; |
||
131 | } |
||
132 | |||
133 | return $lbConf; |
||
134 | } |
||
135 | |||
166 |
This check looks for the bodies 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
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.