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

Method readData

lib/Datasource/Github.php:126–250  ·  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

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected