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