Conditions | 9 |
Paths | 10 |
Total Lines | 91 |
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 |
||
83 | public static function onExtensionFunction() { |
||
84 | |||
85 | if ( !defined( 'SMW_VERSION' ) ) { |
||
86 | |||
87 | if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
||
88 | die( "\nThe 'Semantic Result Formats' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); |
||
89 | } else { |
||
90 | die( |
||
91 | '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticResultFormats/">Semantic Result Formats</a> ' . |
||
92 | 'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be ' . |
||
93 | 'installed and enabled.<br />' |
||
94 | ); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | // Admin Links hook needs to be called in a delayed way so that it |
||
99 | // will always be called after SMW's Admin Links addition; as of |
||
100 | // SMW 1.9, SMW delays calling all its hook functions. |
||
101 | $GLOBALS['wgHooks']['AdminLinks'][] = 'SRFHooks::addToAdminLinks'; |
||
102 | |||
103 | $GLOBALS['srfgScriptPath'] = ( $GLOBALS['wgExtensionAssetsPath'] === false ? $GLOBALS['wgScriptPath'] . '/extensions' : $GLOBALS['wgExtensionAssetsPath'] ) . '/SemanticResultFormats'; |
||
104 | |||
105 | $formatClasses = [ |
||
106 | // Assign the Boilerplate class to a format identifier |
||
107 | // 'boilerplate' => 'SRFBoilerplate', |
||
108 | 'timeline' => 'SRFTimeline', |
||
109 | 'eventline' => 'SRFTimeline', |
||
110 | 'vcard' => 'SRF\vCard\vCardFileExportPrinter', |
||
111 | 'icalendar' => 'SRF\iCalendar\iCalendarFileExportPrinter', |
||
112 | 'bibtex' => 'SRFBibTeX', |
||
113 | 'calendar' => 'SRFCalendar', |
||
114 | 'eventcalendar' => 'SRF\EventCalendar', |
||
115 | 'outline' => 'SRFOutline', |
||
116 | 'sum' => 'SRFMath', |
||
117 | 'product' => 'SRFMath', |
||
118 | 'average' => 'SRFMath', |
||
119 | 'min' => 'SRFMath', |
||
120 | 'max' => 'SRFMath', |
||
121 | 'median' => 'SRFMath', |
||
122 | 'exhibit' => 'SRFExhibit', |
||
123 | 'googlebar' => 'SRFGoogleBar', |
||
124 | 'googlepie' => 'SRFGooglePie', |
||
125 | 'jitgraph' => 'SRFJitGraph', |
||
126 | 'jqplotchart' => 'SRFjqPlotChart', |
||
127 | 'jqplotseries' => 'SRFjqPlotSeries', |
||
128 | 'graph' => 'SRFGraph', |
||
129 | 'process' => 'SRFProcess', |
||
130 | 'gallery' => 'SRF\Gallery', |
||
131 | 'tagcloud' => 'SRF\TagCloud', |
||
132 | 'valuerank' => 'SRFValueRank', |
||
133 | 'array' => 'SRFArray', |
||
134 | 'hash' => 'SRFHash', |
||
135 | 'd3chart' => 'SRFD3Chart', |
||
136 | 'tree' => 'SRF\Formats\Tree\TreeResultPrinter', |
||
137 | 'ultree' => 'SRF\Formats\Tree\TreeResultPrinter', |
||
138 | 'oltree' => 'SRF\Formats\Tree\TreeResultPrinter', |
||
139 | 'filtered' => 'SRF\Filtered\Filtered', |
||
140 | 'latest' => 'SRFTime', |
||
141 | 'earliest' => 'SRFTime', |
||
142 | 'slideshow' => 'SRFSlideShow', |
||
143 | 'timeseries' => 'SRFTimeseries', |
||
144 | 'sparkline' => 'SRFSparkline', |
||
145 | 'listwidget' => 'SRFListWidget', |
||
146 | 'pagewidget' => 'SRFPageWidget', |
||
147 | 'dygraphs' => 'SRFDygraphs', |
||
148 | 'incoming' => 'SRFIncoming', |
||
149 | 'media' => 'SRF\MediaPlayer', |
||
150 | 'excel' => 'SRF\SRFExcel', |
||
151 | 'datatables' => 'SRF\DataTables' |
||
152 | ]; |
||
153 | |||
154 | $formatAliases = [ |
||
155 | 'tagcloud' => [ 'tag cloud' ], |
||
156 | 'datatables' => [ 'datatable' ], |
||
157 | 'valuerank' => [ 'value rank' ], |
||
158 | 'd3chart' => [ 'd3 chart' ], |
||
159 | 'timeseries' => [ 'time series' ], |
||
160 | 'jqplotchart' => [ 'jqplot chart', 'jqplotpie', 'jqplotbar' ], |
||
161 | 'jqplotseries' => [ 'jqplot series' ], |
||
162 | ]; |
||
163 | |||
164 | foreach ( $GLOBALS['srfgFormats'] as $format ) { |
||
165 | if ( array_key_exists( $format, $formatClasses ) ) { |
||
166 | $GLOBALS['smwgResultFormats'][$format] = $formatClasses[$format]; |
||
167 | |||
168 | if ( isset( $GLOBALS['smwgResultAliases'] ) && array_key_exists( $format, $formatAliases ) ) { |
||
169 | $GLOBALS['smwgResultAliases'][$format] = $formatAliases[$format]; |
||
170 | } |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | |||
185 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.