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