MCPcopy Create free account
hub / github.com/Rello/analytics / readData

Method readData

lib/Datasource/Github.php:134–263  ·  view source on GitHub ↗

* Read the Data * @param $option * @return array available options of the data source */

($option)

Source from the content-addressed store, hash-verified

132 * @return array available options of the data source
133 */
134 public function readData($option): array {
135 $data = array();
136 $header = array();
137 $cache = $this->getCacheMetadata($option);
138
139 if ($cache['notModified'] === true) {
140 return [
141 'header' => [],
142 'dimensions' => [],
143 'data' => [],
144 'rawdata' => null,
145 'error' => 0,
146 'cache' => $cache,
147 ];
148 }
149
150 if (!isset($option['data']) || $option['data'] === 'release') {
151 $url = 'https://api.github.com/repos/' . $option['user'] . '/' . $option['repository'] . '/releases';
152 $curlResult = $this->getJsonData($url, $option);
153 $http_code = $curlResult['http_code'];
154 // Check for HTTP error code
155 if ($http_code < 200 || $http_code >= 300) {
156 return $this->buildHttpErrorResult($http_code, $curlResult, $cache);
157 }
158 $i = 0;
159 if (isset($option['filter'])) {
160 $extensions = explode(',', $option['filter']); // ['gz', 'pkg', 'tbz', 'msi', 'AppImage']
161 } else {
162 $extensions = [''];
163 }
164
165 foreach ($curlResult['data'] as $item) {
166 foreach ($item['assets'] as $asset) {
167 $extension = pathinfo($asset['name'], PATHINFO_EXTENSION);
168 if (in_array($extension, $extensions) || $extensions === ['']) {
169 if (isset($option['limit']) and $option['limit'] !== '') {
170 if ($i === (int)$option['limit']) break;
171 }
172 $nc_value = $asset['download_count'];
173 if (isset($option['showAssets']) and $option['showAssets'] === 'true') {
174 $data[] = [$item['tag_name'], $asset['name'], $this->floatvalue($nc_value)];
175 } else {
176 $data[] = [$item['tag_name'], $this->floatvalue($nc_value)];
177 }
178 $i++;
179 }
180 }
181 }
182
183 $header[] = $this->l10n->t('Version');
184 if (isset($option['showAssets']) and $option['showAssets'] === 'true') {
185 // TRANSLATORS: Noun: a downloadable file attached to a GitHub release.
186 $header[] = $this->l10n->t('Asset');
187 }
188 $header[] = $this->l10n->t('Download count');
189 } else if ($option['data'] === 'package') {
190 $url = $this->buildPackageVersionsUrl($option);
191 $curlResult = $this->getRawData($url, $option);

Callers

nothing calls this directly

Calls 9

getCacheMetadataMethod · 0.95
getJsonDataMethod · 0.95
buildHttpErrorResultMethod · 0.95
floatvalueMethod · 0.95
getRawDataMethod · 0.95
countFunction · 0.50
tMethod · 0.45

Tested by

no test coverage detected