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