Conditions | 6 |
Paths | 10 |
Total Lines | 57 |
Code Lines | 46 |
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 |
||
30 | static public function getScriptData( $sPathOrContent, $sType='plugin', $aDefaultHeaderKeys=array() ) { |
||
31 | |||
32 | $_aHeaderKeys = $aDefaultHeaderKeys + array( |
||
33 | // storing array key => the comment entry header label |
||
34 | 'sName' => 'Name', |
||
35 | 'sURI' => 'URI', |
||
36 | 'sScriptName' => 'Script Name', |
||
37 | 'sLibraryName' => 'Library Name', |
||
38 | 'sLibraryURI' => 'Library URI', |
||
39 | 'sPluginName' => 'Plugin Name', |
||
40 | 'sPluginURI' => 'Plugin URI', |
||
41 | 'sThemeName' => 'Theme Name', |
||
42 | 'sThemeURI' => 'Theme URI', |
||
43 | 'sVersion' => 'Version', |
||
44 | 'sDescription' => 'Description', |
||
45 | 'sAuthor' => 'Author', |
||
46 | 'sAuthorURI' => 'Author URI', |
||
47 | 'sTextDomain' => 'Text Domain', |
||
48 | 'sDomainPath' => 'Domain Path', |
||
49 | 'sNetwork' => 'Network', |
||
50 | // Site Wide Only is deprecated in favour of Network. |
||
51 | '_sitewide' => 'Site Wide Only', |
||
52 | ); |
||
53 | |||
54 | $aData = file_exists( $sPathOrContent ) |
||
55 | ? get_file_data( |
||
56 | $sPathOrContent, |
||
57 | $_aHeaderKeys, |
||
58 | $sType // context |
||
59 | ) |
||
60 | : self::getScriptDataFromContents( |
||
61 | $sPathOrContent, |
||
62 | $sType, |
||
63 | $_aHeaderKeys |
||
64 | ); |
||
65 | |||
66 | switch ( trim( $sType ) ) { |
||
67 | case 'theme': |
||
68 | $aData['sName'] = $aData['sThemeName']; |
||
69 | $aData['sURI'] = $aData['sThemeURI']; |
||
70 | break; |
||
71 | case 'library': |
||
72 | $aData['sName'] = $aData['sLibraryName']; |
||
73 | $aData['sURI'] = $aData['sLibraryURI']; |
||
74 | break; |
||
75 | case 'script': |
||
76 | $aData['sName'] = $aData['sScriptName']; |
||
77 | break; |
||
78 | case 'plugin': |
||
79 | $aData['sName'] = $aData['sPluginName']; |
||
80 | $aData['sURI'] = $aData['sPluginURI']; |
||
81 | break; |
||
82 | default: |
||
83 | break; |
||
84 | } |
||
85 | |||
86 | return $aData; |
||
87 | |||
206 |