feat(v4.0.0): 175 WCAG 2.2 & ARIA rules, VPAT 2.5, 11 presets, PolicyEngine, inline suppressions, cache, CI generator, PHPUnit assertions, and open-source YakNet identity

This commit is contained in:
Enes Yakıştır
2026-11-21 09:48:29 +03:00
parent ef8ccb9f75
commit 5680882bee
114 changed files with 8875 additions and 325 deletions
+81
View File
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace YakNet\AccessibilityConsole\Reporting;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use YakNet\AccessibilityConsole\Core\Severity;
use YakNet\AccessibilityConsole\Core\Violation;
/**
* Formats accessibility violations in standard Checkstyle XML format
* for integration with Jenkins, PhpStorm, SonarQube, and GitLab CI.
*/
class CheckstyleFormatter implements FormatterInterface
{
/**
* @param Violation[] $violations
* @param int $baselinedCount
* @param SymfonyStyle $io
* @return int
*/
public function format(array $violations, int $baselinedCount, SymfonyStyle $io): int
{
$io->write($this->render($violations));
return empty($violations) ? Command::SUCCESS : Command::FAILURE;
}
/**
* Render Checkstyle XML string.
*
* @param Violation[] $violations
*/
public function render(array $violations): string
{
/** @var array<string, Violation[]> $grouped */
$grouped = [];
foreach ($violations as $v) {
$file = $v->location['file'] ?? 'unknown';
$grouped[$file][] = $v;
}
$xml = [];
$xml[] = '<?xml version="1.0" encoding="UTF-8"?>';
$xml[] = '<checkstyle version="4.0.0">';
foreach ($grouped as $file => $fileViolations) {
$xml[] = sprintf(' <file name="%s">', $this->escapeAttr($file));
foreach ($fileViolations as $v) {
$line = isset($v->location['line']) ? max(1, (int)$v->location['line']) : 1;
$col = isset($v->location['column']) ? max(1, (int)$v->location['column']) : 1;
$sev = match ($v->severity) {
Severity::CRITICAL, Severity::ERROR => 'error',
Severity::WARNING => 'warning',
Severity::INFO => 'info',
};
$source = 'YakNet.Accessibility.' . $v->ruleId;
$xml[] = sprintf(
' <error line="%d" column="%d" severity="%s" message="%s" source="%s"/>',
$line,
$col,
$sev,
$this->escapeAttr($v->message),
$this->escapeAttr($source)
);
}
$xml[] = ' </file>';
}
$xml[] = '</checkstyle>';
return implode("\n", $xml) . "\n";
}
private function escapeAttr(string $value): string
{
return htmlspecialchars($value, ENT_XML1 | ENT_QUOTES, 'UTF-8');
}
}
+323 -41
View File
@@ -6,11 +6,16 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
use YakNet\AccessibilityConsole\Analytics\ComplianceMatrixGenerator;
use YakNet\AccessibilityConsole\Core\Violation;
use YakNet\AccessibilityConsole\Reference\WcagDatabase;
class ExcelReportExporter
{
/**
* Export WCAG audit results as an Excel (.xlsx) workbook.
* Export WCAG audit results as a multi-tab Excel (.xlsx) workbook.
*
* @param array<string, mixed> $scanResult
* @param string $targetUrl
@@ -22,65 +27,342 @@ class ExcelReportExporter
throw new \RuntimeException('To export Excel audit reports, please install phpspreadsheet via: composer require phpoffice/phpspreadsheet');
}
date_default_timezone_set('Europe/Istanbul');
/** @var int $score */
$score = is_numeric($scanResult['score'] ?? null) ? intval($scanResult['score']) : 0;
/** @var array<int, array<string, mixed>> $violations */
$violations = is_array($scanResult['violations'] ?? null) ? $scanResult['violations'] : [];
$violationsCount = count($violations);
$dateStr = date('d.m.Y H:i:s');
$reportId = 'YAK-A11Y-' . date('Ymd') . '-' . strtoupper(substr(md5($targetUrl . date('Ymd')), 0, 6));
// Severity counters
$criticalCount = 0;
$warningCount = 0;
$infoCount = 0;
foreach ($violations as $v) {
$rawSev = $v['severity'] ?? 'ERROR';
$sev = strtoupper(is_scalar($rawSev) ? (string)$rawSev : 'ERROR');
if ($sev === 'ERROR' || $sev === 'CRITICAL') {
$criticalCount++;
} elseif ($sev === 'WARNING' || $sev === 'WARN') {
$warningCount++;
} else {
$infoCount++;
}
}
// Compliance Matrix
$rawMatrix = $scanResult['complianceMatrix'] ?? null;
/** @var array<string, mixed>|null $matrix */
$matrix = is_array($rawMatrix) ? $rawMatrix : null;
if (!$matrix) {
$gen = new ComplianceMatrixGenerator();
$pseudoViolations = [];
foreach ($violations as $v) {
$rawStd = $v['standard'] ?? 'WCAG 2.1 AA';
$stdStr = is_scalar($rawStd) ? (string)$rawStd : 'WCAG 2.1 AA';
$std = match($stdStr) {
'A' => \YakNet\AccessibilityConsole\Core\WCAGStandard::A,
'AAA' => \YakNet\AccessibilityConsole\Core\WCAGStandard::AAA,
default => \YakNet\AccessibilityConsole\Core\WCAGStandard::AA,
};
$rawRule = $v['ruleId'] ?? '';
$ruleId = is_scalar($rawRule) ? (string)$rawRule : '';
$rawDesc = $v['description'] ?? '';
$desc = is_scalar($rawDesc) ? (string)$rawDesc : '';
$rawLine = $v['line'] ?? 0;
$line = is_numeric($rawLine) ? (int)$rawLine : 0;
$rawSnippet = $v['htmlSnippet'] ?? '';
$snippet = is_scalar($rawSnippet) ? (string)$rawSnippet : '';
$pseudoViolations[] = new Violation(
ruleId: $ruleId,
message: $desc,
severity: \YakNet\AccessibilityConsole\Core\Severity::ERROR,
standard: $std,
location: ['line' => $line],
htmlSnippet: $snippet
);
}
$matrix = $gen->generate($pseudoViolations, max(1, count($violations)));
}
$rawPrinciples = (isset($matrix['principles']) && is_array($matrix['principles']))
? $matrix['principles']
: [
'Perceivable' => ['violations' => 0, 'status' => 'Pass'],
'Operable' => ['violations' => 0, 'status' => 'Pass'],
'Understandable' => ['violations' => 0, 'status' => 'Pass'],
'Robust' => ['violations' => 0, 'status' => 'Pass'],
];
$statusText = $score >= 80 ? 'WCAG 2.1 AA Uyumlu (Pass)' : ($score >= 50 ? 'İyileştirme Gerekli (Warning)' : 'Kritik İhlaller (Fail)');
$scoreHexColor = $score >= 80 ? '059669' : ($score >= 50 ? 'D97706' : 'DC2626');
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Erişilebilirlik Raporu');
// Headers
$sheet->setCellValue('A1', 'YakNet Accessibility Console - WCAG 2.1 Audit Export');
$sheet->mergeCells('A1:F1');
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
$sheet->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
// -------------------------------------------------------------
// SHEET 1: ÖZET VE DENETİM KARNESİ (Executive Summary)
// -------------------------------------------------------------
$sheetSummary = $spreadsheet->getActiveSheet();
$sheetSummary->setTitle('Denetim Özeti & Karne');
$sheetSummary->setShowGridLines(true);
$sheet->setCellValue('A3', 'Hedef URL / Dizin:');
$sheet->setCellValue('B3', $targetUrl);
$sheet->setCellValue('A4', 'WCAG Skoru:');
$sheet->setCellValue('B4', $score . ' / 100');
$sheet->setCellValue('A5', 'İhlal Sayısı:');
$sheet->setCellValue('B5', count($violations));
// Header Banner
$sheetSummary->setCellValue('A1', '♿ YAKNET ACCESSIBILITY CONSOLE — ERİŞİLEBİLİRLİK DENETİM RAPORU');
$sheetSummary->mergeCells('A1:F1');
$sheetSummary->getStyle('A1')->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FFFFFF');
$sheetSummary->getStyle('A1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('0F172A');
$sheetSummary->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
$sheetSummary->getRowDimension(1)->setRowHeight(32);
$sheetSummary->setCellValue('A2', 'WCAG 2.1 / 2.2 Uyumluluk ve Erişilebilirlik Karnesi (YakNet Open Source)');
$sheetSummary->mergeCells('A2:F2');
$sheetSummary->getStyle('A2')->getFont()->setSize(10)->getColor()->setRGB('64748B');
$sheetSummary->getStyle('A2')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetSummary->getRowDimension(2)->setRowHeight(20);
// Metadata Table
$sheetSummary->setCellValue('A4', 'Rapor Bilgileri');
$sheetSummary->mergeCells('A4:B4');
$sheetSummary->getStyle('A4')->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetSummary->getStyle('A4')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('1E293B');
$metaRows = [
['Rapor Referans No', $reportId],
['Denetlenen Web Adresi', $targetUrl],
['Denetim Zamanı', $dateStr],
['Denetim Standardı', 'W3C WCAG 2.1 / 2.2 (Level AA) & EN 301 549'],
['Denetim Motoru', 'YakNet Accessibility Console v4.0'],
];
$r = 5;
foreach ($metaRows as $m) {
$sheetSummary->setCellValue("A{$r}", $m[0]);
$sheetSummary->setCellValue("B{$r}", $m[1]);
$sheetSummary->getStyle("A{$r}")->getFont()->setBold(true)->getColor()->setRGB('334155');
$sheetSummary->getStyle("A{$r}:B{$r}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->getColor()->setRGB('CBD5E1');
$r++;
}
// Score KPI Card (Columns D:F, Rows 4:7)
$sheetSummary->setCellValue('D4', 'Genel Sağlık Skoru');
$sheetSummary->mergeCells('D4:F4');
$sheetSummary->getStyle('D4')->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetSummary->getStyle('D4')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('1E293B');
$sheetSummary->getStyle('D4')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetSummary->setCellValue('D5', $score . ' / 100');
$sheetSummary->mergeCells('D5:F6');
$sheetSummary->getStyle('D5')->getFont()->setBold(true)->setSize(24)->getColor()->setRGB($scoreHexColor);
$sheetSummary->getStyle('D5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
$sheetSummary->getStyle('D5:F6')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('F8FAFC');
$sheetSummary->setCellValue('D7', $statusText);
$sheetSummary->mergeCells('D7:F7');
$sheetSummary->getStyle('D7')->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetSummary->getStyle('D7')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB($scoreHexColor);
$sheetSummary->getStyle('D7')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetSummary->getStyle('D4:F7')->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_MEDIUM)->getColor()->setRGB($scoreHexColor);
// Findings Statistics Table (Row 11)
$sheetSummary->setCellValue('A11', 'İhlal Dağılım İstatistikleri');
$sheetSummary->mergeCells('A11:C11');
$sheetSummary->getStyle('A11')->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetSummary->getStyle('A11')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('1E293B');
$statRows = [
['Toplam İhlal Sayısı', $violationsCount, '0F172A'],
['Kritik Hatalar (Error)', $criticalCount, 'DC2626'],
['Uyarılar (Warning)', $warningCount, 'D97706'],
['Bilgilendirmeler (Info)', $infoCount, '2563EB'],
];
$r = 12;
foreach ($statRows as $st) {
$sheetSummary->setCellValue("A{$r}", $st[0]);
$sheetSummary->mergeCells("A{$r}:B{$r}");
$sheetSummary->setCellValue("C{$r}", $st[1]);
$sheetSummary->getStyle("A{$r}")->getFont()->setBold(true);
$sheetSummary->getStyle("C{$r}")->getFont()->setBold(true)->getColor()->setRGB($st[2]);
$sheetSummary->getStyle("C{$r}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetSummary->getStyle("A{$r}:C{$r}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->getColor()->setRGB('CBD5E1');
$r++;
}
// WCAG 4 Principles Table (Row 11, Cols D:F)
$sheetSummary->setCellValue('D11', 'WCAG 2.1 Dört Temel İlke Dağılımı');
$sheetSummary->mergeCells('D11:F11');
$sheetSummary->getStyle('D11')->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetSummary->getStyle('D11')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('1E293B');
$principleTr = [
'Perceivable' => '1. Algılanabilir (Perceivable)',
'Operable' => '2. Çalıştırılabilir (Operable)',
'Understandable' => '3. Anlaşılabilir (Understandable)',
'Robust' => '4. Sağlam (Robust)'
];
$r = 12;
foreach ($rawPrinciples as $pKey => $pData) {
$pKeyStr = (string)$pKey;
$pName = $principleTr[$pKeyStr] ?? $pKeyStr;
$vNum = (is_array($pData) && isset($pData['violations']) && is_numeric($pData['violations'])) ? (int)$pData['violations'] : 0;
$sheetSummary->setCellValue("D{$r}", $pName);
$sheetSummary->setCellValue("E{$r}", $vNum . ' İhlal');
$sheetSummary->setCellValue("F{$r}", $vNum === 0 ? '✓ Geçti' : '⚠ İncele');
$sheetSummary->getStyle("F{$r}")->getFont()->setBold(true)->getColor()->setRGB($vNum === 0 ? '059669' : 'DC2626');
$sheetSummary->getStyle("D{$r}:F{$r}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->getColor()->setRGB('CBD5E1');
$r++;
}
$sheetSummary->getColumnDimension('A')->setWidth(22);
$sheetSummary->getColumnDimension('B')->setWidth(38);
$sheetSummary->getColumnDimension('C')->setWidth(14);
$sheetSummary->getColumnDimension('D')->setWidth(26);
$sheetSummary->getColumnDimension('E')->setWidth(14);
$sheetSummary->getColumnDimension('F')->setWidth(18);
// -------------------------------------------------------------
// SHEET 2: TÜM İHLAL DETAYLARI (Detailed Violations Table)
// -------------------------------------------------------------
$sheetViolations = $spreadsheet->createSheet();
$sheetViolations->setTitle('İhlal Detayları');
$sheetViolations->setShowGridLines(true);
$vHeaders = ['#', 'Kural ID', 'Standart', 'Ciddiyet', 'Satır', 'İhlal Açıklaması', 'Hatalı Kod Snippet', 'Çözüm ve Düzeltme Önerisi'];
$vCols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
// Table Header
$row = 7;
$headers = ['#', 'Kural ID', 'Standart', 'Ciddiyet', 'İhlal Açıklaması', 'Kod Snippet'];
$cols = ['A', 'B', 'C', 'D', 'E', 'F'];
foreach ($headers as $i => $h) {
$col = $cols[$i];
$sheet->setCellValue("{$col}{$row}", $h);
$sheet->getStyle("{$col}{$row}")->getFont()->setBold(true);
$sheet->getStyle("{$col}{$row}")->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('1E293B');
$sheet->getStyle("{$col}{$row}")->getFont()->getColor()->setRGB('FFFFFF');
$vRow = 1;
foreach ($vHeaders as $i => $h) {
$col = $vCols[$i];
$sheetViolations->setCellValue("{$col}{$vRow}", $h);
$sheetViolations->getStyle("{$col}{$vRow}")->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetViolations->getStyle("{$col}{$vRow}")->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('0F172A');
$sheetViolations->getStyle("{$col}{$vRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
}
$sheetViolations->getRowDimension($vRow)->setRowHeight(28);
// Table Rows
// Populate Table Rows
$vRow = 2;
foreach ($violations as $idx => $v) {
/** @var array<string, mixed> $v */
$r = $row + 1 + intval($idx);
$ruleId = is_string($v['ruleId'] ?? null) ? $v['ruleId'] : '';
$standard = is_string($v['standard'] ?? null) ? $v['standard'] : 'WCAG 2.1';
$severity = is_string($v['severity'] ?? null) ? $v['severity'] : 'WARNING';
$desc = is_string($v['description'] ?? null) ? $v['description'] : '';
$snippet = is_string($v['htmlSnippet'] ?? null) ? $v['htmlSnippet'] : '';
$rawRule = $v['ruleId'] ?? '';
$ruleId = is_scalar($rawRule) ? (string)$rawRule : '';
$rawStd = $v['standard'] ?? 'WCAG 2.1 AA';
$standard = is_scalar($rawStd) ? (string)$rawStd : 'WCAG 2.1 AA';
$rawSev = $v['severity'] ?? 'ERROR';
$severity = strtoupper(is_scalar($rawSev) ? (string)$rawSev : 'ERROR');
$rawLine = $v['line'] ?? 0;
$line = is_numeric($rawLine) ? (int)$rawLine : 0;
$rawDesc = $v['description'] ?? '';
$desc = is_scalar($rawDesc) ? (string)$rawDesc : '';
$rawSnippet = $v['htmlSnippet'] ?? '';
$snippet = is_scalar($rawSnippet) ? (string)$rawSnippet : '';
$rawSug = $v['suggestion'] ?? '';
$suggestion = is_scalar($rawSug) ? (string)$rawSug : '';
$sheet->setCellValue("A{$r}", intval($idx) + 1);
$sheet->setCellValue("B{$r}", $ruleId);
$sheet->setCellValue("C{$r}", $standard);
$sheet->setCellValue("D{$r}", $severity);
$sheet->setCellValue("E{$r}", $desc);
$sheet->setCellValue("F{$r}", $snippet);
$isCrit = ($severity === 'ERROR' || $severity === 'CRITICAL');
$sevLabel = $isCrit ? 'KRİTİK' : 'UYARI';
$sevColor = $isCrit ? 'DC2626' : 'D97706';
$rowBg = ($idx % 2 === 1) ? 'F8FAFC' : 'FFFFFF';
$sheetViolations->setCellValue("A{$vRow}", $idx + 1);
$sheetViolations->setCellValue("B{$vRow}", $ruleId);
$sheetViolations->setCellValue("C{$vRow}", $standard);
$sheetViolations->setCellValue("D{$vRow}", $sevLabel);
$sheetViolations->setCellValue("E{$vRow}", $line > 0 ? $line : '-');
$sheetViolations->setCellValue("F{$vRow}", $desc);
$sheetViolations->setCellValue("G{$vRow}", $snippet);
$sheetViolations->setCellValue("H{$vRow}", $suggestion);
// Row styling
$sheetViolations->getStyle("A{$vRow}:H{$vRow}")->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB($rowBg);
$sheetViolations->getStyle("A{$vRow}:H{$vRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->getColor()->setRGB('E2E8F0');
$sheetViolations->getStyle("A{$vRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetViolations->getStyle("C{$vRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetViolations->getStyle("D{$vRow}")->getFont()->setBold(true)->getColor()->setRGB($sevColor);
$sheetViolations->getStyle("D{$vRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetViolations->getStyle("E{$vRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
// Monospace font for code snippet
$sheetViolations->getStyle("G{$vRow}")->getFont()->setName('Consolas')->setSize(9.5);
$sheetViolations->getStyle("F{$vRow}")->getAlignment()->setWrapText(true);
$sheetViolations->getStyle("G{$vRow}")->getAlignment()->setWrapText(true);
$sheetViolations->getStyle("H{$vRow}")->getAlignment()->setWrapText(true);
$sheetViolations->getRowDimension($vRow)->setRowHeight(36);
$vRow++;
}
// Auto-fit columns
foreach ($cols as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
// Enable auto-filter
if ($vRow > 2) {
$sheetViolations->setAutoFilter("A1:H" . ($vRow - 1));
}
$sheetViolations->getColumnDimension('A')->setWidth(6);
$sheetViolations->getColumnDimension('B')->setWidth(26);
$sheetViolations->getColumnDimension('C')->setWidth(14);
$sheetViolations->getColumnDimension('D')->setWidth(12);
$sheetViolations->getColumnDimension('E')->setWidth(8);
$sheetViolations->getColumnDimension('F')->setWidth(40);
$sheetViolations->getColumnDimension('G')->setWidth(35);
$sheetViolations->getColumnDimension('H')->setWidth(40);
// -------------------------------------------------------------
// SHEET 3: STANDARTLAR VE KURALLAR KATALOĞU (Rules Reference)
// -------------------------------------------------------------
$sheetRules = $spreadsheet->createSheet();
$sheetRules->setTitle('WCAG Kural Kataloğu');
$sheetRules->setShowGridLines(true);
WcagDatabase::load();
$criteria = WcagDatabase::all();
$sheetRules->setCellValue('A1', '#');
$sheetRules->setCellValue('B1', 'Kural Kodu');
$sheetRules->setCellValue('C1', 'WCAG Kriteri');
$sheetRules->setCellValue('D1', 'Seviye');
$sheetRules->setCellValue('E1', 'Açıklama');
$sheetRules->setCellValue('F1', 'W3C Resmi Kılavuz Bağlantısı');
$sheetRules->getStyle('A1:F1')->getFont()->setBold(true)->getColor()->setRGB('FFFFFF');
$sheetRules->getStyle('A1:F1')->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB('0F172A');
$sheetRules->getRowDimension(1)->setRowHeight(26);
$rRow = 2;
$idx = 1;
foreach ($criteria as $code => $cr) {
$sheetRules->setCellValue("A{$rRow}", $idx);
$sheetRules->setCellValue("B{$rRow}", $cr->id);
$sheetRules->setCellValue("C{$rRow}", $cr->title);
$sheetRules->setCellValue("D{$rRow}", $cr->level);
$sheetRules->setCellValue("E{$rRow}", $cr->description);
$sheetRules->setCellValue("F{$rRow}", $cr->url);
$sheetRules->getStyle("A{$rRow}:F{$rRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN)->getColor()->setRGB('E2E8F0');
$sheetRules->getStyle("D{$rRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$sheetRules->getStyle("F{$rRow}")->getFont()->getColor()->setRGB('2563EB');
$sheetRules->getStyle("F{$rRow}")->getFont()->setUnderline(true);
$rRow++;
$idx++;
}
$sheetRules->getColumnDimension('A')->setWidth(6);
$sheetRules->getColumnDimension('B')->setWidth(26);
$sheetRules->getColumnDimension('C')->setWidth(24);
$sheetRules->getColumnDimension('D')->setWidth(10);
$sheetRules->getColumnDimension('E')->setWidth(50);
$sheetRules->getColumnDimension('F')->setWidth(40);
// Set active sheet back to Summary
$spreadsheet->setActiveSheetIndex(0);
$writer = new Xlsx($spreadsheet);
ob_start();
$writer->save('php://output');
+270 -51
View File
@@ -4,13 +4,15 @@ namespace YakNet\AccessibilityConsole\Reporting;
use Dompdf\Dompdf;
use Dompdf\Options;
use YakNet\AccessibilityConsole\Analytics\ComplianceMatrixGenerator;
use YakNet\AccessibilityConsole\Core\Violation;
class PdfReportGenerator
{
/**
* Generate a PDF Accessibility Certificate & Audit Report.
* Generate a detailed PDF Accessibility Audit & Conformance Report.
*
* @param array<string, mixed> $scanResult Scan result metrics and violations array
* @param array<string, mixed> $scanResult Scan result metrics, compliance matrix, and violations array
* @param string $targetUrl Target URL or file name audited
* @return string Raw PDF binary data
*/
@@ -28,32 +30,150 @@ class PdfReportGenerator
/** @var array<int, array<string, mixed>> $violations */
$violations = is_array($scanResult['violations'] ?? null) ? $scanResult['violations'] : [];
$violationsCount = count($violations);
$dateStr = date('d.m.Y H:i');
$dateStr = date('d.m.Y H:i:s');
$reportId = 'YAK-A11Y-' . date('Ymd') . '-' . strtoupper(substr(md5($targetUrl . date('Ymd')), 0, 6));
$scoreColor = $score >= 80 ? '#10b981' : ($score >= 50 ? '#f59e0b' : '#ef4444');
$statusText = $score >= 80 ? 'WCAG 2.1 AA Uyumlu (Pass)' : ($score >= 50 ? 'İyileştirme Gerekli (Warning)' : 'Kritik İhlaller (Fail)');
// Calculate severity counts
$criticalCount = 0;
$warningCount = 0;
$infoCount = 0;
foreach ($violations as $v) {
$rawSev = $v['severity'] ?? 'ERROR';
$sev = strtoupper(is_scalar($rawSev) ? (string)$rawSev : 'ERROR');
if ($sev === 'ERROR' || $sev === 'CRITICAL') {
$criticalCount++;
} elseif ($sev === 'WARNING' || $sev === 'WARN') {
$warningCount++;
} else {
$infoCount++;
}
}
// Compliance Matrix (Principles and Levels)
$rawMatrix = $scanResult['complianceMatrix'] ?? null;
/** @var array<string, mixed>|null $matrix */
$matrix = is_array($rawMatrix) ? $rawMatrix : null;
if (!$matrix) {
$gen = new ComplianceMatrixGenerator();
$pseudoViolations = [];
foreach ($violations as $v) {
$rawStd = $v['standard'] ?? 'WCAG 2.1 AA';
$stdStr = is_scalar($rawStd) ? (string)$rawStd : 'WCAG 2.1 AA';
$std = match($stdStr) {
'A' => \YakNet\AccessibilityConsole\Core\WCAGStandard::A,
'AAA' => \YakNet\AccessibilityConsole\Core\WCAGStandard::AAA,
default => \YakNet\AccessibilityConsole\Core\WCAGStandard::AA,
};
$rawRule = $v['ruleId'] ?? '';
$ruleId = is_scalar($rawRule) ? (string)$rawRule : '';
$rawDesc = $v['description'] ?? '';
$desc = is_scalar($rawDesc) ? (string)$rawDesc : '';
$rawLine = $v['line'] ?? 0;
$line = is_numeric($rawLine) ? (int)$rawLine : 0;
$rawSnippet = $v['htmlSnippet'] ?? '';
$snippet = is_scalar($rawSnippet) ? (string)$rawSnippet : '';
$pseudoViolations[] = new Violation(
ruleId: $ruleId,
message: $desc,
severity: \YakNet\AccessibilityConsole\Core\Severity::ERROR,
standard: $std,
location: ['line' => $line],
htmlSnippet: $snippet
);
}
$matrix = $gen->generate($pseudoViolations, max(1, count($violations)));
}
$scoreColor = $score >= 80 ? '#059669' : ($score >= 50 ? '#d97706' : '#dc2626');
$scoreBg = $score >= 80 ? '#ecfdf5' : ($score >= 50 ? '#fffbeb' : '#fef2f2');
$statusText = $score >= 80 ? 'WCAG 2.1 AA UYUMLU (PASS)' : ($score >= 50 ? 'KISMİ UYUMLU - İYİLEŞTİRME GEREKLİ' : 'UYUMSUZ - KRİTİK İHLALLER MEVCUT');
$rawPrinciples = (isset($matrix['principles']) && is_array($matrix['principles']))
? $matrix['principles']
: [
'Perceivable' => ['violations' => 0, 'status' => 'Pass'],
'Operable' => ['violations' => 0, 'status' => 'Pass'],
'Understandable' => ['violations' => 0, 'status' => 'Pass'],
'Robust' => ['violations' => 0, 'status' => 'Pass'],
];
$principleTrNames = [
'Perceivable' => '1. Algılanabilir (Perceivable)',
'Operable' => '2. Çalıştırılabilir (Operable)',
'Understandable' => '3. Anlaşılabilir (Understandable)',
'Robust' => '4. Sağlam (Robust)'
];
// Build Principles Table Rows
$principlesRowsHtml = '';
foreach ($rawPrinciples as $pKey => $pData) {
$pKeyStr = (string)$pKey;
$name = $principleTrNames[$pKeyStr] ?? $pKeyStr;
$vCount = (is_array($pData) && isset($pData['violations']) && is_numeric($pData['violations'])) ? (int)$pData['violations'] : 0;
$statusBadge = $vCount === 0
? "<span style='color:#059669; font-weight:bold;'>✓ Başarılı</span>"
: "<span style='color:#dc2626; font-weight:bold;'>⚠ {$vCount} İhlal</span>";
$principlesRowsHtml .= "
<tr>
<td style='padding:7px 10px; border-bottom:1px solid #e2e8f0; font-weight:600;'>{$name}</td>
<td style='padding:7px 10px; border-bottom:1px solid #e2e8f0; text-align:center;'>{$vCount}</td>
<td style='padding:7px 10px; border-bottom:1px solid #e2e8f0; text-align:center;'>{$statusBadge}</td>
</tr>";
}
// Build Violations Detailed Listing (All Violations)
$violationsHtml = '';
$slicedViolations = array_slice($violations, 0, 25);
foreach ($slicedViolations as $idx => $v) {
/** @var array<string, mixed> $v */
$num = $idx + 1;
$ruleIdVal = is_string($v['ruleId'] ?? null) ? $v['ruleId'] : '';
$descVal = is_string($v['description'] ?? null) ? $v['description'] : '';
$snippetVal = is_string($v['htmlSnippet'] ?? null) ? $v['htmlSnippet'] : '';
$suggestionVal = is_string($v['suggestion'] ?? null) ? $v['suggestion'] : '';
$ruleId = htmlspecialchars($ruleIdVal);
$desc = htmlspecialchars($descVal);
$snippet = htmlspecialchars($snippetVal);
$suggestion = htmlspecialchars($suggestionVal);
$violationsHtml .= "
<div style='margin-bottom:12px; padding:10px; border-left:4px solid #ef4444; background:#f8fafc;'>
<div style='font-weight:bold; color:#0f172a; font-size:12px;'>#{$num} [{$ruleId}] {$desc}</div>
<div style='font-family:monospace; font-size:10px; color:#e11d48; margin:4px 0; background:#f1f5f9; padding:4px;'>{$snippet}</div>
<div style='font-size:11px; color:#475569;'><b>Öneri:</b> {$suggestion}</div>
if ($violationsCount === 0) {
$violationsHtml = "
<div style='background:#ecfdf5; border:1px solid #a7f3d0; border-radius:6px; padding:16px; text-align:center; color:#065f46; margin-top:15px;'>
<div style='font-size:16px; font-weight:bold;'>🎉 Tebrikler! Hiçbir Erişilebilirlik İhlali Tespit Edilmedi</div>
<div style='font-size:11px; margin-top:4px;'>Bu web sayfası W3C WCAG 2.1 standartlarına tam uyumluluk göstermektedir.</div>
</div>";
} else {
foreach ($violations as $idx => $v) {
$num = $idx + 1;
$rawRule = $v['ruleId'] ?? '';
$ruleId = htmlspecialchars(is_scalar($rawRule) ? (string)$rawRule : '');
$rawDesc = $v['description'] ?? '';
$desc = htmlspecialchars(is_scalar($rawDesc) ? (string)$rawDesc : '');
$rawSnippet = $v['htmlSnippet'] ?? '';
$snippet = htmlspecialchars(is_scalar($rawSnippet) ? (string)$rawSnippet : '');
$rawSug = $v['suggestion'] ?? 'İlgili erişilebilirlik kuralını W3C standartlarına uygun olarak düzeltin.';
$suggestion = htmlspecialchars(is_scalar($rawSug) ? (string)$rawSug : '');
$rawStd = $v['standard'] ?? 'WCAG 2.1 AA';
$standard = htmlspecialchars(is_scalar($rawStd) ? (string)$rawStd : 'WCAG 2.1 AA');
$rawSev = $v['severity'] ?? 'ERROR';
$severity = strtoupper(is_scalar($rawSev) ? (string)$rawSev : 'ERROR');
$rawLine = $v['line'] ?? 0;
$line = is_numeric($rawLine) ? (int)$rawLine : 0;
$sevBadgeColor = ($severity === 'ERROR' || $severity === 'CRITICAL') ? '#dc2626' : '#d97706';
$sevBgColor = ($severity === 'ERROR' || $severity === 'CRITICAL') ? '#fef2f2' : '#fffbeb';
$sevText = ($severity === 'ERROR' || $severity === 'CRITICAL') ? 'KRİTİK HATA' : 'UYARI';
$violationsHtml .= "
<div style='page-break-inside:avoid; margin-bottom:12px; border:1px solid #e2e8f0; border-left:4px solid {$sevBadgeColor}; border-radius:4px; background:#ffffff;'>
<div style='padding:8px 12px; background:{$sevBgColor}; border-bottom:1px solid #e2e8f0;'>
<span style='font-weight:bold; color:#0f172a; font-size:11px;'>#{$num} [{$ruleId}]</span>
<span style='float:right;'>
<span style='background:#0f172a; color:#ffffff; padding:2px 6px; border-radius:3px; font-size:9px; font-weight:bold;'>{$standard}</span>
<span style='background:{$sevBadgeColor}; color:#ffffff; padding:2px 6px; border-radius:3px; font-size:9px; font-weight:bold;'>{$sevText}</span>
" . ($line > 0 ? "<span style='color:#64748b; font-size:9px; margin-left:6px;'>Satır: {$line}</span>" : "") . "
</span>
</div>
<div style='padding:10px 12px;'>
<div style='color:#1e293b; font-size:11px; margin-bottom:6px;'><b>İhlal Açıklaması:</b> {$desc}</div>
" . (!empty($snippet) ? "
<div style='background:#f8fafc; border:1px solid #cbd5e1; border-radius:3px; padding:6px 8px; font-family:monospace; font-size:9.5px; color:#be123c; margin-bottom:6px; word-wrap:break-word;'>
{$snippet}
</div>" : "") . "
<div style='color:#0f766e; font-size:10.5px; background:#f0fdfa; padding:6px 8px; border-radius:3px;'>
<b>💡 Çözüm ve Düzeltme Önerisi:</b> {$suggestion}
</div>
</div>
</div>";
}
}
$html = "
@@ -61,50 +181,149 @@ class PdfReportGenerator
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>WCAG 2.1 Erişilebilirlik Sertifikası ve Raporu</title>
<title>YakNet Erişilebilirlik Denetim Raporu</title>
<style>
* { font-family: 'DejaVu Sans', sans-serif; }
body { font-family: 'DejaVu Sans', sans-serif; color: #1e293b; line-height: 1.5; font-size: 11px; margin: 0; padding: 20px; }
.header { text-align: center; border-bottom: 2px solid #38bdf8; padding-bottom: 15px; margin-bottom: 20px; }
.title { font-size: 18px; font-weight: bold; color: #0f172a; }
.subtitle { font-size: 12px; color: #64748b; margin-top: 4px; }
.badge { display: inline-block; padding: 6px 16px; border-radius: 12px; color: #fff; font-weight: bold; font-size: 13px; background: {$scoreColor}; }
.grid { margin-bottom: 20px; }
.card { background: #f8fafc; border: 1px solid #e2e8f0; padding: 12px; border-radius: 6px; margin-bottom: 10px; }
.footer { text-align: center; border-top: 1px solid #e2e8f0; padding-top: 15px; font-size: 10px; color: #94a3b8; margin-top: 30px; }
@page { margin: 16mm 14mm 16mm 14mm; }
* { font-family: 'DejaVu Sans', sans-serif; box-sizing: border-box; }
body { color: #0f172a; line-height: 1.45; font-size: 10.5px; margin: 0; padding: 0; }
.header-table { width: 100%; border-collapse: collapse; border-bottom: 2px solid #0f172a; padding-bottom: 10px; margin-bottom: 14px; }
.brand-title { font-size: 16px; font-weight: bold; color: #0f172a; letter-spacing: 0.5px; }
.brand-sub { font-size: 9.5px; color: #475569; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
.report-meta { text-align: right; font-size: 9.5px; color: #475569; }
.scorecard-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.score-box { background: {$scoreBg}; border: 1.5px solid {$scoreColor}; border-radius: 6px; padding: 12px; text-align: center; }
.score-number { font-size: 34px; font-weight: bold; color: {$scoreColor}; line-height: 1; }
.score-status-badge { display: inline-block; background: {$scoreColor}; color: #ffffff; padding: 4px 12px; border-radius: 12px; font-weight: bold; font-size: 10.5px; margin-top: 6px; }
.info-table { width: 100%; border-collapse: collapse; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; }
.info-table td { padding: 6px 10px; font-size: 10px; border-bottom: 1px solid #e2e8f0; }
.section-header { font-size: 12px; font-weight: bold; color: #0f172a; border-bottom: 1.5px solid #cbd5e1; padding-bottom: 4px; margin: 16px 0 10px 0; text-transform: uppercase; letter-spacing: 0.5px; }
.matrix-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.matrix-table th { background: #1e293b; color: #ffffff; padding: 7px 10px; font-size: 10px; font-weight: bold; text-align: left; }
.footer-table { width: 100%; border-collapse: collapse; border-top: 1px solid #cbd5e1; padding-top: 10px; margin-top: 20px; font-size: 8.5px; color: #64748b; }
.signature-box { border: 1px dashed #94a3b8; background: #f8fafc; border-radius: 4px; padding: 10px; text-align: center; margin-top: 15px; }
</style>
</head>
<body>
<div class='header'>
<div class='title'>♿ YakNet Accessibility Console</div>
<div class='subtitle'>WCAG 2.1 AA Erişilebilirlik Uyumluluk Raporu</div>
<!-- Başlık -->
<table class='header-table'>
<tr>
<td style='vertical-align:middle;'>
<div class='brand-title'>♿ YAKNET</div>
<div class='brand-sub'>Open-Source Accessibility Console • yak.net.tr</div>
</td>
<td class='report-meta' style='vertical-align:middle;'>
<div><b>Rapor Ref:</b> {$reportId}</div>
<div><b>Tarih:</b> {$dateStr}</div>
<div><b>Standart:</b> W3C WCAG 2.1 / 2.2 (Level AA)</div>
</td>
</tr>
</table>
<!-- Başlık -->
<div style='text-align:center; margin-bottom:14px;'>
<div style='font-size:15px; font-weight:bold; color:#0f172a; text-transform:uppercase;'>WEB ERİŞİLEBİLİRLİK DENETİM VE UYUMLULUK RAPORU</div>
<div style='font-size:9.5px; color:#64748b; margin-top:2px;'>W3C Web İçeriği Erişilebilirlik Kılavuzları (WCAG 2.1 &amp; 2.2) Uyarınca Hazırlanmıştır</div>
</div>
<div class='card' style='text-align:center;'>
<div style='font-size:11px; color:#64748b; text-transform:uppercase;'>Erişilebilirlik Sağlık Skoru</div>
<div style='font-size:32px; font-weight:bold; color:{$scoreColor}; margin:6px 0;'>{$score} / 100</div>
<div class='badge'>{$statusText}</div>
</div>
<!-- Skor ve Denetim Bilgisi Kartları -->
<table class='scorecard-table'>
<tr>
<td style='width:38%; vertical-align:top; padding-right:10px;'>
<div class='score-box'>
<div style='font-size:9.5px; font-weight:bold; color:#64748b; text-transform:uppercase;'>Genel Sağlık Skoru</div>
<div class='score-number'>{$score}<span style='font-size:16px; color:#64748b; font-weight:normal;'>/100</span></div>
<div class='score-status-badge'>{$statusText}</div>
</div>
</td>
<td style='width:62%; vertical-align:top;'>
<table class='info-table'>
<tr>
<td style='width:35%; font-weight:bold; color:#475569;'>Hedef URL / Adres:</td>
<td style='font-weight:bold; color:#0f172a; word-break:break-all;'>" . htmlspecialchars($targetUrl) . "</td>
</tr>
<tr>
<td style='font-weight:bold; color:#475569;'>Denetim Zamanı:</td>
<td>{$dateStr}</td>
</tr>
<tr>
<td style='font-weight:bold; color:#475569;'>Toplam İhlal Sayısı:</td>
<td><b>{$violationsCount}</b> Adet (Kritik: <b style='color:#dc2626;'>{$criticalCount}</b>, Uyarı: <b style='color:#d97706;'>{$warningCount}</b>)</td>
</tr>
<tr>
<td style='font-weight:bold; color:#475569;'>Denetim Motoru:</td>
<td>YakNet Accessibility Console v4.0</td>
</tr>
</table>
</td>
</tr>
</table>
<div class='card'>
<div><b>Hedef URL / Dizin:</b> " . htmlspecialchars($targetUrl) . "</div>
<div><b>Tarama Tarihi:</b> {$dateStr}</div>
<div><b>Tespit Edilen İhlal Sayısı:</b> {$violationsCount} Hata</div>
<div><b>Raporu Üreten Motor:</b> YakNet AI & Accessibility Engine v3.3</div>
</div>
<!-- WCAG 4 Temel Prensip Uyumluluk Karnesi -->
<div class='section-header'>📊 WCAG 2.1 Dört Temel İlke ve Uyumluluk Karnesi</div>
<table class='matrix-table'>
<thead>
<tr>
<th style='width:60%;'>WCAG Temel İlkesi</th>
<th style='width:20%; text-align:center;'>İhlal Sayısı</th>
<th style='width:20%; text-align:center;'>Durum</th>
</tr>
</thead>
<tbody>
{$principlesRowsHtml}
</tbody>
</table>
<h3 style='color:#0f172a; border-bottom:1px solid #cbd5e1; padding-bottom:6px;'>📋 Erişilebilirlik İhlalleri ve Çözüm Detayları</h3>
<!-- Detaylı İhlal Listesi -->
<div class='section-header'>📋 Tespit Edilen Erişilebilirlik Bulguları ve Çözüm Planı ({$violationsCount} Kayıt)</div>
{$violationsHtml}
<div class='footer'>
© {$dateStr} YakNet Bilişim — Türkiye'nin Yerli & Milli Erişilebilirlik Platformu (yak.net.tr)
<!-- Doğrulama ve Rapor Özeti Bölümü -->
<div style='page-break-inside:avoid; margin-top:20px;'>
<div class='signature-box'>
<div style='font-weight:bold; font-size:10.5px; color:#0f172a;'>YAKNET ACCESSIBILITY CONSOLE — OTOMATİK DENETİM DOĞRULAMASI</div>
<div style='font-size:9px; color:#475569; margin:4px 0 8px 0;'>
Bu rapor, yukarıda belirtilen hedef için W3C Web Content Accessibility Guidelines (WCAG 2.1 / 2.2),
WAI-ARIA 1.2 ve EN 301 549 kılavuzlarına dayalı açık kaynaklı otomatik denetim sonucunu yansıtmaktadır.
</div>
<table style='width:100%; margin-top:8px;'>
<tr>
<td style='text-align:left; font-size:9px; color:#64748b;'>
<b>Doğrulama Özeti (SHA-256):</b> " . hash('sha256', $reportId . $targetUrl) . "<br>
<b>Organizasyon:</b> YakNet (Open Source)
</td>
<td style='text-align:right; font-size:9px;'>
<div style='font-weight:bold; color:#0f172a;'>YakNet Accessibility Console</div>
<div style='color:#059669; font-weight:bold;'>[ Otomatik Doğrulama Özeti Oluşturuldu ]</div>
</td>
</tr>
</table>
</div>
</div>
<!-- Alt Bilgi -->
<table class='footer-table'>
<tr>
<td style='text-align:left;'>
YakNet Accessibility Console • Açık Kaynak Erişilebilirlik Denetim Platformu • https://forum.yak.net.tr
</td>
<td style='text-align:right;'>
Belge No: {$reportId}
</td>
</tr>
</table>
</body>
</html>";
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true);
$options->set('defaultFont', 'DejaVu Sans');
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
+1 -1
View File
@@ -124,7 +124,7 @@ class SarifFormatter implements FormatterInterface
'driver' => [
'name' => 'YakNet Accessibility Console',
'informationUri' => 'https://forum.yak.net.tr',
'semanticVersion' => '3.3.0',
'semanticVersion' => '4.0.0',
'rules' => array_values($rulesMap),
],
],