Conditions | 15 |
Paths | 400 |
Total Lines | 108 |
Code Lines | 65 |
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 |
||
39 | public function runRefresh(string $crontag = null): void |
||
40 | { |
||
41 | $sets = $this->modconfig->getArray('sets'); |
||
42 | /** @var string $datadir */ |
||
43 | $datadir = $this->config->getPathValue('datadir', 'data/'); |
||
44 | $stateFile = $datadir . 'metarefresh-state.php'; |
||
45 | |||
46 | foreach ($sets as $setkey => $set) { |
||
47 | $set = Configuration::loadFromArray($set); |
||
48 | |||
49 | // Only process sets where cron matches the current cron tag |
||
50 | $cronTags = $set->getArray('cron'); |
||
51 | if ($crontag !== null && !in_array($crontag, $cronTags, true)) { |
||
52 | Logger::debug('[metarefresh]: Skipping set [' . $setkey . '], not allowed for cron tag ' . $tag); |
||
|
|||
53 | continue; |
||
54 | } |
||
55 | |||
56 | Logger::info('[metarefresh]: Executing set [' . $setkey . ']'); |
||
57 | |||
58 | $expireAfter = $set->getOptionalInteger('expireAfter', null); |
||
59 | if ($expireAfter !== null) { |
||
60 | $expire = time() + $expireAfter; |
||
61 | } else { |
||
62 | $expire = null; |
||
63 | } |
||
64 | |||
65 | $outputDir = $set->getString('outputDir'); |
||
66 | $outputDir = $this->config->resolvePath($outputDir); |
||
67 | if ($outputDir === null) { |
||
68 | throw new Exception("Invalid outputDir specified."); |
||
69 | } |
||
70 | |||
71 | $outputFormat = $set->getValueValidate('outputFormat', ['flatfile', 'serialize'], 'flatfile'); |
||
72 | |||
73 | $oldMetadataSrc = MetaDataStorageSource::getSource([ |
||
74 | 'type' => $outputFormat, |
||
75 | 'directory' => $outputDir, |
||
76 | ]); |
||
77 | |||
78 | $metaloader = new MetaLoader($expire, $stateFile, $oldMetadataSrc); |
||
79 | |||
80 | // Get global blacklist, whitelist, attributewhitelist and caching info |
||
81 | $blacklist = $this->modconfig->getOptionalArray('blacklist', []); |
||
82 | $whitelist = $this->modconfig->getOptionalArray('whitelist', []); |
||
83 | $attributewhitelist = $this->modconfig->getOptionalArray('attributewhitelist', []); |
||
84 | $conditionalGET = $this->modconfig->getOptionalBoolean('conditionalGET', false); |
||
85 | |||
86 | // get global type filters |
||
87 | $available_types = [ |
||
88 | 'saml20-idp-remote', |
||
89 | 'saml20-sp-remote', |
||
90 | 'attributeauthority-remote' |
||
91 | ]; |
||
92 | $set_types = $set->getOptionalArray('types', $available_types); |
||
93 | |||
94 | foreach ($set->getArray('sources') as $source) { |
||
95 | // filter metadata by type of entity |
||
96 | if (isset($source['types'])) { |
||
97 | $metaloader->setTypes($source['types']); |
||
98 | } else { |
||
99 | $metaloader->setTypes($set_types); |
||
100 | } |
||
101 | |||
102 | // Merge global and src specific blacklists |
||
103 | if (isset($source['blacklist'])) { |
||
104 | $source['blacklist'] = array_unique(array_merge($source['blacklist'], $blacklist)); |
||
105 | } else { |
||
106 | $source['blacklist'] = $blacklist; |
||
107 | } |
||
108 | |||
109 | // Merge global and src specific whitelists |
||
110 | if (isset($source['whitelist'])) { |
||
111 | $source['whitelist'] = array_unique(array_merge($source['whitelist'], $whitelist)); |
||
112 | } else { |
||
113 | $source['whitelist'] = $whitelist; |
||
114 | } |
||
115 | |||
116 | # Merge global and src specific attributewhitelists: cannot use array_unique for multi-dim. |
||
117 | if (isset($source['attributewhitelist'])) { |
||
118 | $source['attributewhitelist'] = array_merge($source['attributewhitelist'], $attributewhitelist); |
||
119 | } else { |
||
120 | $source['attributewhitelist'] = $attributewhitelist; |
||
121 | } |
||
122 | |||
123 | // Let src specific conditionalGET override global one |
||
124 | if (!isset($source['conditionalGET'])) { |
||
125 | $source['conditionalGET'] = $conditionalGET; |
||
126 | } |
||
127 | |||
128 | Logger::debug('[metarefresh]: In set [' . $setkey . '] loading source [' . $source['src'] . ']'); |
||
129 | $metaloader->loadSource($source); |
||
130 | } |
||
131 | |||
132 | // Write state information back to disk |
||
133 | $metaloader->writeState(); |
||
134 | |||
135 | switch ($outputFormat) { |
||
136 | case 'flatfile': |
||
137 | $metaloader->writeMetadataFiles($outputDir); |
||
138 | break; |
||
139 | case 'serialize': |
||
140 | $metaloader->writeMetadataSerialize($outputDir); |
||
141 | break; |
||
142 | } |
||
143 | |||
144 | if ($set->hasValue('arp')) { |
||
145 | $arpconfig = Configuration::loadFromArray($set->getValue('arp')); |
||
146 | $metaloader->writeARPfile($arpconfig); |
||
147 | } |
||
151 |