| Conditions | 48 |
| Paths | > 20000 |
| Total Lines | 127 |
| Code Lines | 82 |
| Lines | 21 |
| Ratio | 16.54 % |
| 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 |
||
| 47 | public function parse($file) { |
||
| 48 | if (!file_exists($file)) { |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | if(!is_null($this->cache)) { |
||
| 53 | $fileCacheKey = $file . filemtime($file); |
||
| 54 | if ($cachedValue = $this->cache->get($fileCacheKey)) { |
||
| 55 | return json_decode($cachedValue, true); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | libxml_use_internal_errors(true); |
||
| 60 | $loadEntities = libxml_disable_entity_loader(false); |
||
| 61 | $xml = simplexml_load_file($file); |
||
| 62 | |||
| 63 | libxml_disable_entity_loader($loadEntities); |
||
| 64 | if ($xml === false) { |
||
| 65 | libxml_clear_errors(); |
||
| 66 | return null; |
||
| 67 | } |
||
| 68 | $array = $this->xmlToArray($xml); |
||
|
|
|||
| 69 | |||
| 70 | if (is_null($array)) { |
||
| 71 | return null; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!array_key_exists('info', $array)) { |
||
| 75 | $array['info'] = []; |
||
| 76 | } |
||
| 77 | if (!array_key_exists('remote', $array)) { |
||
| 78 | $array['remote'] = []; |
||
| 79 | } |
||
| 80 | if (!array_key_exists('public', $array)) { |
||
| 81 | $array['public'] = []; |
||
| 82 | } |
||
| 83 | if (!array_key_exists('types', $array)) { |
||
| 84 | $array['types'] = []; |
||
| 85 | } |
||
| 86 | if (!array_key_exists('repair-steps', $array)) { |
||
| 87 | $array['repair-steps'] = []; |
||
| 88 | } |
||
| 89 | if (!array_key_exists('install', $array['repair-steps'])) { |
||
| 90 | $array['repair-steps']['install'] = []; |
||
| 91 | } |
||
| 92 | if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
||
| 93 | $array['repair-steps']['pre-migration'] = []; |
||
| 94 | } |
||
| 95 | if (!array_key_exists('post-migration', $array['repair-steps'])) { |
||
| 96 | $array['repair-steps']['post-migration'] = []; |
||
| 97 | } |
||
| 98 | if (!array_key_exists('live-migration', $array['repair-steps'])) { |
||
| 99 | $array['repair-steps']['live-migration'] = []; |
||
| 100 | } |
||
| 101 | if (!array_key_exists('uninstall', $array['repair-steps'])) { |
||
| 102 | $array['repair-steps']['uninstall'] = []; |
||
| 103 | } |
||
| 104 | if (!array_key_exists('background-jobs', $array)) { |
||
| 105 | $array['background-jobs'] = []; |
||
| 106 | } |
||
| 107 | if (!array_key_exists('two-factor-providers', $array)) { |
||
| 108 | $array['two-factor-providers'] = []; |
||
| 109 | } |
||
| 110 | if (!array_key_exists('commands', $array)) { |
||
| 111 | $array['commands'] = []; |
||
| 112 | } |
||
| 113 | if (!array_key_exists('activity', $array)) { |
||
| 114 | $array['activity'] = []; |
||
| 115 | } |
||
| 116 | if (!array_key_exists('filters', $array['activity'])) { |
||
| 117 | $array['activity']['filters'] = []; |
||
| 118 | } |
||
| 119 | if (!array_key_exists('settings', $array['activity'])) { |
||
| 120 | $array['activity']['settings'] = []; |
||
| 121 | } |
||
| 122 | if (!array_key_exists('providers', $array['activity'])) { |
||
| 123 | $array['activity']['providers'] = []; |
||
| 124 | } |
||
| 125 | |||
| 126 | if (array_key_exists('types', $array)) { |
||
| 127 | if (is_array($array['types'])) { |
||
| 128 | foreach ($array['types'] as $type => $v) { |
||
| 129 | unset($array['types'][$type]); |
||
| 130 | if (is_string($type)) { |
||
| 131 | $array['types'][] = $type; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } else { |
||
| 135 | $array['types'] = []; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | View Code Duplication | if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
| 139 | $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
||
| 140 | } |
||
| 141 | View Code Duplication | if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
| 142 | $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
||
| 143 | } |
||
| 144 | View Code Duplication | if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
| 145 | $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
||
| 146 | } |
||
| 147 | View Code Duplication | if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
| 148 | $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
||
| 149 | } |
||
| 150 | View Code Duplication | if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
| 151 | $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
||
| 152 | } |
||
| 153 | View Code Duplication | if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
| 154 | $array['background-jobs'] = $array['background-jobs']['job']; |
||
| 155 | } |
||
| 156 | View Code Duplication | if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
| 157 | $array['commands'] = $array['commands']['command']; |
||
| 158 | } |
||
| 159 | if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
||
| 160 | $array['activity']['filters'] = $array['activity']['filters']['filter']; |
||
| 161 | } |
||
| 162 | if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
||
| 163 | $array['activity']['settings'] = $array['activity']['settings']['setting']; |
||
| 164 | } |
||
| 165 | if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
||
| 166 | $array['activity']['providers'] = $array['activity']['providers']['provider']; |
||
| 167 | } |
||
| 168 | |||
| 169 | if(!is_null($this->cache)) { |
||
| 170 | $this->cache->set($fileCacheKey, json_encode($array)); |
||
| 171 | } |
||
| 172 | return $array; |
||
| 173 | } |
||
| 174 | |||
| 227 |