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

Method parsePackageDownloadRows

lib/Datasource/Github.php:322–354  ·  view source on GitHub ↗
(string $html, array $option)

Source from the content-addressed store, hash-verified

320 }
321
322 private function parsePackageDownloadRows(string $html, array $option): array {
323 $rows = [];
324 $limit = isset($option['limit']) && $option['limit'] !== '' ? (int)$option['limit'] : 0;
325
326 preg_match_all('/<li\b[^>]*class="[^"]*\bBox-row\b[^"]*"[^>]*>(.*?)<\/li>/is', $html, $matches);
327 foreach ($matches[1] as $rowHtml) {
328 preg_match_all('/<a\b[^>]*class="[^"]*\bLabel\b[^"]*"[^>]*>(.*?)<\/a>/is', $rowHtml, $tagMatches);
329 if ($tagMatches[1] === []) {
330 continue;
331 }
332
333 if (!preg_match('/octicon-download.*?<\/svg>\s*([\d,.]+)/is', $rowHtml, $downloadMatch)) {
334 continue;
335 }
336
337 $downloads = $this->parseDownloadCount($downloadMatch[1]);
338 foreach ($tagMatches[1] as $tagHtml) {
339 $tag = trim(html_entity_decode(strip_tags($tagHtml), ENT_QUOTES | ENT_HTML5));
340 if ($tag !== '') {
341 $rows[] = [
342 'tag' => $tag,
343 'downloads' => $downloads,
344 ];
345 }
346
347 if ($limit > 0 && count($rows) >= $limit) {
348 return $rows;
349 }
350 }
351 }
352
353 return $rows;
354 }
355
356 private function parseDownloadCount(string $value): int {
357 $digits = preg_replace('/\D+/', '', $value);

Callers 1

readDataMethod · 0.95

Calls 2

parseDownloadCountMethod · 0.95
countFunction · 0.50

Tested by

no test coverage detected