| Conditions | 10 |
| Paths | 295 |
| Total Lines | 84 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 80 | public function main(Request $request): Template |
||
|
|
|||
| 81 | { |
||
| 82 | $this->authUtils::requireAdmin(); |
||
| 83 | |||
| 84 | Logger::setCaptureLog(true); |
||
| 85 | $sets = $this->module_config->getArray('sets', []); |
||
| 86 | |||
| 87 | foreach ($sets as $setkey => $set) { |
||
| 88 | $set = Configuration::loadFromArray($set); |
||
| 89 | |||
| 90 | Logger::info('[metarefresh]: Executing set [' . $setkey . ']'); |
||
| 91 | |||
| 92 | try { |
||
| 93 | $expireAfter = $set->getInteger('expireAfter', null); |
||
| 94 | if ($expireAfter !== null) { |
||
| 95 | $expire = time() + $expireAfter; |
||
| 96 | } else { |
||
| 97 | $expire = null; |
||
| 98 | } |
||
| 99 | $metaloader = new MetaLoader($expire); |
||
| 100 | |||
| 101 | // Get global black/whitelists |
||
| 102 | $blacklist = $mconfig->getArray('blacklist', []); |
||
| 103 | $whitelist = $mconfig->getArray('whitelist', []); |
||
| 104 | |||
| 105 | // get global type filters |
||
| 106 | $available_types = [ |
||
| 107 | 'saml20-idp-remote', |
||
| 108 | 'saml20-sp-remote', |
||
| 109 | 'attributeauthority-remote' |
||
| 110 | ]; |
||
| 111 | $set_types = $set->getArrayize('types', $available_types); |
||
| 112 | |||
| 113 | foreach ($set->getArray('sources') as $source) { |
||
| 114 | // filter metadata by type of entity |
||
| 115 | if (isset($source['types'])) { |
||
| 116 | $metaloader->setTypes($source['types']); |
||
| 117 | } else { |
||
| 118 | $metaloader->setTypes($set_types); |
||
| 119 | } |
||
| 120 | |||
| 121 | // Merge global and src specific blacklists |
||
| 122 | if (isset($source['blacklist'])) { |
||
| 123 | $source['blacklist'] = array_unique(array_merge($source['blacklist'], $blacklist)); |
||
| 124 | } else { |
||
| 125 | $source['blacklist'] = $blacklist; |
||
| 126 | } |
||
| 127 | |||
| 128 | // Merge global and src specific whitelists |
||
| 129 | if (isset($source['whitelist'])) { |
||
| 130 | $source['whitelist'] = array_unique(array_merge($source['whitelist'], $whitelist)); |
||
| 131 | } else { |
||
| 132 | $source['whitelist'] = $whitelist; |
||
| 133 | } |
||
| 134 | |||
| 135 | Logger::debug( |
||
| 136 | '[metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']' |
||
| 137 | ); |
||
| 138 | $metaloader->loadSource($source); |
||
| 139 | } |
||
| 140 | |||
| 141 | $outputDir = $set->getString('outputDir'); |
||
| 142 | $outputDir = Utils\System::resolvePath($outputDir); |
||
| 143 | |||
| 144 | $outputFormat = $set->getValueValidate('outputFormat', ['flatfile', 'serialize'], 'flatfile'); |
||
| 145 | switch ($outputFormat) { |
||
| 146 | case 'flatfile': |
||
| 147 | $metaloader->writeMetadataFiles($outputDir); |
||
| 148 | break; |
||
| 149 | case 'serialize': |
||
| 150 | $metaloader->writeMetadataSerialize($outputDir); |
||
| 151 | break; |
||
| 152 | } |
||
| 153 | } catch (Exception $e) { |
||
| 154 | $e = Error\Exception::fromException($e); |
||
| 155 | $e->logWarning(); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | $logentries = Logger::getCapturedLog(); |
||
| 160 | |||
| 161 | $t = new Template($this->config, 'metarefresh:fetch.twig'); |
||
| 162 | $t->data['logentries'] = $logentries; |
||
| 163 | return $t; |
||
| 164 | } |
||
| 166 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.