Extract Lighthouse findings
This commit is contained in:
@@ -55,6 +55,22 @@ $categoryIds = [
|
||||
|
||||
$scores = [];
|
||||
|
||||
$auditCategories = [];
|
||||
|
||||
foreach ($categoryIds as $categoryId) {
|
||||
$auditRefs = $data['categories'][$categoryId]['auditRefs'] ?? [];
|
||||
|
||||
foreach ($auditRefs as $auditRef) {
|
||||
$auditId = $auditRef['id'] ?? null;
|
||||
|
||||
if ($auditId === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$auditCategories[$auditId][] = $categoryId;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($categoryIds as $categoryId) {
|
||||
$rawScore = $data['categories'][$categoryId]['score'] ?? null;
|
||||
|
||||
@@ -72,10 +88,45 @@ foreach ($categoryIds as $categoryId) {
|
||||
];
|
||||
}
|
||||
|
||||
$findings = [];
|
||||
|
||||
$skipModes = [
|
||||
'notApplicable',
|
||||
'informative',
|
||||
'manual',
|
||||
'error',
|
||||
];
|
||||
|
||||
foreach ($data['audits'] ?? [] as $auditId => $audit) {
|
||||
$score = $audit['score'] ?? null;
|
||||
$scoreDisplayMode = $audit['scoreDisplayMode'] ?? null;
|
||||
|
||||
if ($score === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($scoreDisplayMode, $skipModes, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_numeric($score) || $score >= 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$findings[] = [
|
||||
'id' => $auditId,
|
||||
'categories' => $auditCategories[$auditId] ?? [],
|
||||
'title' => $audit['title'] ?? $auditId,
|
||||
'problem' => $audit['description'] ?? '',
|
||||
'impact' => $audit['displayValue'] ?? null,
|
||||
'score' => (int) round($score * 100),
|
||||
];
|
||||
}
|
||||
|
||||
$output = [
|
||||
'schemaVersion' => 1,
|
||||
'scores' => $scores,
|
||||
'findings' => [],
|
||||
'findings' => $findings,
|
||||
];
|
||||
|
||||
$outputJson = json_encode(
|
||||
|
||||
Reference in New Issue
Block a user