| Conditions | 7 | 
| Paths | 8 | 
| Total Lines | 59 | 
| Code Lines | 45 | 
| 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 | ||
| 31 |     static public function getPHPInfo() { | ||
| 32 | |||
| 33 |         if ( isset( self::$_aPHPInfo ) ) { | ||
| 34 | return self::$_aPHPInfo; | ||
| 35 | } | ||
| 36 | |||
| 37 | ob_start(); | ||
| 38 | phpinfo( -1 ); | ||
| 39 | |||
| 40 | $_sOutput = preg_replace( | ||
| 41 | array( | ||
| 42 | '#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', | ||
| 43 | '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', | ||
| 44 | "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', | ||
| 45 | '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' | ||
| 46 | .'<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', | ||
| 47 | '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', | ||
| 48 | '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', | ||
| 49 | "# +#", | ||
| 50 | '#<tr>#', | ||
| 51 | '#</tr>#' | ||
| 52 | ), | ||
| 53 | array( | ||
| 54 | '$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', | ||
| 55 | '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. | ||
| 56 | "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', | ||
| 57 | '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', | ||
| 58 | '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . '<tr><td>Zend Egg</td><td>$1</td></tr>', | ||
| 59 | ' ', | ||
| 60 | '%S%', | ||
| 61 | '%E%' | ||
| 62 | ), | ||
| 63 | ob_get_clean() | ||
| 64 | ); | ||
| 65 | |||
| 66 | $_aSections = explode( '<h2>', strip_tags( $_sOutput, '<h2><th><td>' ) ); | ||
| 67 | unset( $_aSections[ 0 ] ); | ||
| 68 | |||
| 69 | $_aOutput = array(); | ||
| 70 |         foreach( $_aSections as $_sSection ) { | ||
| 71 | $_iIndex = substr( $_sSection, 0, strpos( $_sSection, '</h2>' ) ); | ||
| 72 | preg_match_all( | ||
| 73 | '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', | ||
| 74 | $_sSection, | ||
| 75 | $_aAskApache, | ||
| 76 | PREG_SET_ORDER | ||
| 77 | ); | ||
| 78 |             foreach( $_aAskApache as $_aMatches ) { | ||
| 79 |                 if ( ! isset( $_aMatches[ 1 ], $_aMatches[ 2 ] ) ) { | ||
| 80 | array_slice( $_aMatches, 2 ); | ||
| 81 | continue; | ||
| 82 | } | ||
| 83 | $_aOutput[ $_iIndex ][ $_aMatches[ 1 ] ] = ! isset( $_aMatches[ 3 ] ) || $_aMatches[ 2 ] == $_aMatches[ 3 ] | ||
| 84 | ? $_aMatches[ 2 ] | ||
| 85 | : array_slice( $_aMatches, 2 ); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | self::$_aPHPInfo = $_aOutput; | ||
| 89 | return self::$_aPHPInfo; | ||
| 90 | |||
| 148 |