Conditions | 2 |
Paths | 2 |
Total Lines | 82 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
48 | public static function initExtension() { |
||
49 | // Register the extension |
||
50 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
51 | 'path' => __FILE__, |
||
52 | 'name' => 'Semantic Watchlist', |
||
53 | 'version' => SWL_VERSION, |
||
54 | 'author' => array( |
||
55 | '[https://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw] for [http://www.wikiworks.com/ WikiWorks]', |
||
56 | '...' |
||
57 | ), |
||
58 | 'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Watchlist', |
||
59 | 'descriptionmsg' => 'semanticwatchlist-desc', |
||
60 | 'license-name' => 'GPL-3.0+' |
||
61 | ); |
||
62 | |||
63 | $GLOBALS['egSwlSqlDatabaseSchemaPath'] = __DIR__ . '/../src/swl-table-schema.sql'; |
||
64 | |||
65 | // Register message files |
||
66 | $GLOBALS['wgMessagesDirs']['SemanticWatchlist'] = __DIR__ . '/../i18n'; |
||
67 | $GLOBALS['wgExtensionMessagesFiles']['SemanticWatchlistAlias'] = __DIR__ . '/../SemanticWatchlist.i18n.alias.php'; |
||
68 | |||
69 | $GLOBALS['egSWLScriptPath'] = $GLOBALS['wgExtensionAssetsPath'] === false ? $GLOBALS['wgScriptPath'] . '/extensions/SemanticWatchlist' : $GLOBALS['wgExtensionAssetsPath'] . '/SemanticWatchlist'; |
||
70 | |||
71 | // wgSpecialPages |
||
72 | $GLOBALS['wgSpecialPages']['SemanticWatchlist'] = 'SpecialSemanticWatchlist'; |
||
73 | $GLOBALS['wgSpecialPageGroups']['SemanticWatchlist'] = 'changes'; |
||
74 | |||
75 | $GLOBALS['wgSpecialPages']['WatchlistConditions'] = 'SpecialWatchlistConditions'; |
||
76 | $GLOBALS['wgSpecialPageGroups']['WatchlistConditions'] = 'changes'; |
||
77 | |||
78 | // wgAPIModules |
||
79 | $GLOBALS['wgAPIModules']['addswlgroup'] = 'ApiAddWatchlistGroup'; |
||
80 | $GLOBALS['wgAPIModules']['deleteswlgroup'] = 'ApiDeleteWatchlistGroup'; |
||
81 | $GLOBALS['wgAPIModules']['editswlgroup'] = 'ApiEditWatchlistGroup'; |
||
82 | $GLOBALS['wgAPIListModules']['semanticwatchlist'] = 'ApiQuerySemanticWatchlist'; |
||
83 | |||
84 | // wgAvailableRights |
||
85 | $GLOBALS['wgAvailableRights'][] = 'semanticwatch'; |
||
86 | $GLOBALS['wgAvailableRights'][] = 'semanticwatchgroups'; |
||
87 | |||
88 | $moduleTemplate = array( |
||
89 | 'localBasePath' => __DIR__ . '/..', |
||
90 | 'remoteBasePath' => $GLOBALS['egSWLScriptPath'] |
||
91 | ); |
||
92 | |||
93 | $GLOBALS['wgResourceModules']['ext.swl.watchlist'] = $moduleTemplate + array( |
||
94 | 'styles' => array( 'specials/ext.swl.watchlist.css' ), |
||
95 | 'scripts' => array(), |
||
96 | 'dependencies' => array(), |
||
97 | 'messages' => array() |
||
98 | ); |
||
99 | |||
100 | $GLOBALS['wgResourceModules']['ext.swl.watchlistconditions'] = $moduleTemplate + array( |
||
101 | 'styles' => array( 'specials/ext.swl.watchlistconditions.css' ), |
||
102 | 'scripts' => array( |
||
103 | 'specials/jquery.watchlistcondition.js', |
||
104 | 'specials/ext.swl.watchlistconditions.js' |
||
105 | ), |
||
106 | 'dependencies' => array(), |
||
107 | 'messages' => array( |
||
108 | 'swl-group-name', |
||
109 | 'swl-group-legend', |
||
110 | 'swl-group-properties', |
||
111 | 'swl-properties-list', |
||
112 | 'swl-group-remove-property', |
||
113 | 'swl-group-add-property', |
||
114 | 'swl-group-page-selection', |
||
115 | 'swl-group-save', |
||
116 | 'swl-group-saved', |
||
117 | 'swl-group-saving', |
||
118 | 'swl-group-remove', |
||
119 | 'swl-group-category', |
||
120 | 'swl-group-namespace', |
||
121 | 'swl-group-concept', |
||
122 | 'swl-group-confirm-remove', |
||
123 | 'swl-custom-legend', |
||
124 | 'swl-custom-remove-property', |
||
125 | 'swl-custom-text-add', |
||
126 | 'swl-custom-input', |
||
127 | ) |
||
128 | ); |
||
129 | } |
||
130 | |||
175 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.