| Conditions | 32 |
| Paths | 231 |
| Total Lines | 155 |
| Lines | 6 |
| Ratio | 3.87 % |
| 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 |
||
| 70 | public function mapConfigArray($id, array $config, $options = 0) |
||
| 71 | { |
||
| 72 | $this->mapReservedScopeArray($id, $config, ConfigResolver::SCOPE_DEFAULT); |
||
| 73 | $this->mapReservedScopeArray($id, $config, ConfigResolver::SCOPE_GLOBAL); |
||
| 74 | $defaultSettings = $this->getContainerParameter( |
||
| 75 | $this->namespace . '.' . ConfigResolver::SCOPE_DEFAULT . '.' . $id, |
||
| 76 | [] |
||
| 77 | ); |
||
| 78 | $globalSettings = $this->getContainerParameter( |
||
| 79 | $this->namespace . '.' . ConfigResolver::SCOPE_GLOBAL . '.' . $id, |
||
| 80 | [] |
||
| 81 | ); |
||
| 82 | |||
| 83 | // (!) Keep siteaccess group settings |
||
| 84 | foreach (array_keys($this->availableSiteAccessGroups) as $scope) { |
||
| 85 | $scopeSettings = array(); |
||
| 86 | View Code Duplication | if (isset($config[$this->siteAccessNodeName][$scope][$id])) { |
|
|
|
|||
| 87 | $scopeSettings = $config[$this->siteAccessNodeName][$scope][$id]; |
||
| 88 | } |
||
| 89 | |||
| 90 | if (empty($scopeSettings)) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($options & static::MERGE_FROM_SECOND_LEVEL) { |
||
| 95 | // array_merge() has to be used because we don't |
||
| 96 | // know whether we have a hash or a plain array |
||
| 97 | $keys1 = array_unique( |
||
| 98 | array_merge( |
||
| 99 | array_keys($defaultSettings), |
||
| 100 | array_keys($scopeSettings), |
||
| 101 | array_keys($globalSettings) |
||
| 102 | ) |
||
| 103 | ); |
||
| 104 | $mergedSettings = array(); |
||
| 105 | foreach ($keys1 as $key) { |
||
| 106 | // Only merge if actual setting is an array. |
||
| 107 | // We assume default setting to be a clear reference for this. |
||
| 108 | // If the setting is not an array, we copy the right value, in respect to the precedence: |
||
| 109 | // 1. global |
||
| 110 | // 3. Group |
||
| 111 | // 4. default |
||
| 112 | if (array_key_exists($key, $defaultSettings) && !is_array($defaultSettings[$key])) { |
||
| 113 | if (array_key_exists($key, $globalSettings)) { |
||
| 114 | $mergedSettings[$key] = $globalSettings[$key]; |
||
| 115 | } elseif (array_key_exists($key, $scopeSettings)) { |
||
| 116 | $mergedSettings[$key] = $scopeSettings[$key]; |
||
| 117 | } else { |
||
| 118 | $mergedSettings[$key] = $defaultSettings[$key]; |
||
| 119 | } |
||
| 120 | } else { |
||
| 121 | $mergedSettings[$key] = array_merge( |
||
| 122 | isset($defaultSettings[$key]) ? $defaultSettings[$key] : array(), |
||
| 123 | isset($scopeSettings[$key]) ? $scopeSettings[$key] : array(), |
||
| 124 | isset($globalSettings[$key]) ? $globalSettings[$key] : array() |
||
| 125 | ); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } else { |
||
| 129 | $mergedSettings = array_merge( |
||
| 130 | $defaultSettings, |
||
| 131 | $scopeSettings, |
||
| 132 | $globalSettings |
||
| 133 | ); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($options & static::UNIQUE) { |
||
| 137 | $mergedSettings = array_values( |
||
| 138 | array_unique($mergedSettings) |
||
| 139 | ); |
||
| 140 | } |
||
| 141 | |||
| 142 | $this->container->setParameter("$this->namespace.$scope.$id", $mergedSettings); |
||
| 143 | } |
||
| 144 | |||
| 145 | foreach ($this->availableSiteAccesses as $scope) { |
||
| 146 | // for a siteaccess, we have to merge the default value, |
||
| 147 | // the group value(s), the siteaccess value and the global |
||
| 148 | // value of the settings. |
||
| 149 | $groupsSettings = []; |
||
| 150 | if (isset($this->groupsBySiteAccess[$scope]) && is_array($this->groupsBySiteAccess[$scope])) { |
||
| 151 | $groupsSettings = $this->groupsArraySetting( |
||
| 152 | $this->groupsBySiteAccess[$scope], |
||
| 153 | $id, |
||
| 154 | $config, |
||
| 155 | $options & static::MERGE_FROM_SECOND_LEVEL |
||
| 156 | ); |
||
| 157 | } |
||
| 158 | |||
| 159 | $scopeSettings = []; |
||
| 160 | View Code Duplication | if (isset($config[$this->siteAccessNodeName][$scope][$id])) { |
|
| 161 | $scopeSettings = $config[$this->siteAccessNodeName][$scope][$id]; |
||
| 162 | } |
||
| 163 | |||
| 164 | if (empty($groupsSettings) && empty($scopeSettings)) { |
||
| 165 | continue; |
||
| 166 | } |
||
| 167 | |||
| 168 | if ($options & static::MERGE_FROM_SECOND_LEVEL) { |
||
| 169 | // array_merge() has to be used because we don't |
||
| 170 | // know whether we have a hash or a plain array |
||
| 171 | $keys1 = array_unique( |
||
| 172 | array_merge( |
||
| 173 | array_keys($defaultSettings), |
||
| 174 | array_keys($groupsSettings), |
||
| 175 | array_keys($scopeSettings), |
||
| 176 | array_keys($globalSettings) |
||
| 177 | ) |
||
| 178 | ); |
||
| 179 | $mergedSettings = []; |
||
| 180 | foreach ($keys1 as $key) { |
||
| 181 | // Only merge if actual setting is an array. |
||
| 182 | // We assume default setting to be a clear reference for this. |
||
| 183 | // If the setting is not an array, we copy the right value, in respect to the precedence: |
||
| 184 | // 1. global |
||
| 185 | // 2. SiteAccess |
||
| 186 | // 3. Group |
||
| 187 | // 4. default |
||
| 188 | if (array_key_exists($key, $defaultSettings) && !is_array($defaultSettings[$key])) { |
||
| 189 | if (array_key_exists($key, $globalSettings)) { |
||
| 190 | $mergedSettings[$key] = $globalSettings[$key]; |
||
| 191 | } elseif (array_key_exists($key, $scopeSettings)) { |
||
| 192 | $mergedSettings[$key] = $scopeSettings[$key]; |
||
| 193 | } elseif (array_key_exists($key, $groupsSettings)) { |
||
| 194 | $mergedSettings[$key] = $groupsSettings[$key]; |
||
| 195 | } else { |
||
| 196 | $mergedSettings[$key] = $defaultSettings[$key]; |
||
| 197 | } |
||
| 198 | } else { |
||
| 199 | $mergedSettings[$key] = array_merge( |
||
| 200 | isset($defaultSettings[$key]) ? $defaultSettings[$key] : [], |
||
| 201 | isset($groupsSettings[$key]) ? $groupsSettings[$key] : [], |
||
| 202 | isset($scopeSettings[$key]) ? $scopeSettings[$key] : [], |
||
| 203 | isset($globalSettings[$key]) ? $globalSettings[$key] : [] |
||
| 204 | ); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } else { |
||
| 208 | $mergedSettings = array_merge( |
||
| 209 | $defaultSettings, |
||
| 210 | $groupsSettings, |
||
| 211 | $scopeSettings, |
||
| 212 | $globalSettings |
||
| 213 | ); |
||
| 214 | } |
||
| 215 | |||
| 216 | if ($options & static::UNIQUE) { |
||
| 217 | $mergedSettings = array_values( |
||
| 218 | array_unique($mergedSettings) |
||
| 219 | ); |
||
| 220 | } |
||
| 221 | |||
| 222 | $this->container->setParameter("$this->namespace.$scope.$id", $mergedSettings); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 363 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.