Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
feat(v3.2.7): expand WCAG ruleset to 127 rules, add HTML syntax linter, single-pass rule engine, template preprocessor, and accessibility analytics
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\AbstractRule;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AccesskeyDuplicate extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_2_1_1_ACCESSKEY_DUPLICATE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'accesskey attribute values must be unique across the document.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(\DOMDocument $doc): array
|
||||
{
|
||||
$violations = [];
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$elements = $xpath->query('//*[@accesskey]');
|
||||
|
||||
if ($elements === false || $elements->length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$keys = [];
|
||||
foreach ($elements as $el) {
|
||||
if (!$el instanceof DOMElement) {
|
||||
continue;
|
||||
}
|
||||
$val = trim($el->getAttribute('accesskey'));
|
||||
if ($val === '') {
|
||||
continue;
|
||||
}
|
||||
if (!isset($keys[$val])) {
|
||||
$keys[$val] = [];
|
||||
}
|
||||
$keys[$val][] = $el;
|
||||
}
|
||||
|
||||
foreach ($keys as $key => $elementsWithKey) {
|
||||
if (count($elementsWithKey) > 1) {
|
||||
foreach ($elementsWithKey as $el) {
|
||||
$violations[] = $this->createViolation(
|
||||
"Duplicate accesskey=\"{$key}\" found. Access keys must be unique across the document.",
|
||||
$el,
|
||||
"Assign a unique accesskey to each interactive element, or avoid using accesskey entirely."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $violations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaBrailleEquivalent extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_BRAILLE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Elements with aria-braillelabel or aria-brailleroledescription must provide a standard accessible equivalent.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if ($element->hasAttribute('aria-braillelabel')) {
|
||||
$hasName = false;
|
||||
if ($element->hasAttribute('aria-label') && trim($element->getAttribute('aria-label')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif ($element->hasAttribute('aria-labelledby') && trim($element->getAttribute('aria-labelledby')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif ($element->hasAttribute('title') && trim($element->getAttribute('title')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif ($element->hasAttribute('alt') && trim($element->getAttribute('alt')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif (trim($element->textContent) !== '') {
|
||||
$hasName = true;
|
||||
}
|
||||
|
||||
if (!$hasName) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element has aria-braillelabel but is missing a standard accessible name (aria-label, aria-labelledby, or text content).",
|
||||
"Add a standard aria-label or aria-labelledby in addition to the aria-braillelabel."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($element->hasAttribute('aria-brailleroledescription')) {
|
||||
if (!$element->hasAttribute('aria-roledescription') || trim($element->getAttribute('aria-roledescription')) === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element has aria-brailleroledescription but is missing the standard aria-roledescription attribute.",
|
||||
"Add an aria-roledescription attribute to accompany aria-brailleroledescription."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaCurrentValid extends AbstractRule
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
private static array $validValues = [
|
||||
'page', 'step', 'location', 'date', 'time', 'true', 'false'
|
||||
];
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_CURRENT';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'The aria-current attribute must have a valid token value.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (!$element->hasAttribute('aria-current')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = strtolower(trim($element->getAttribute('aria-current')));
|
||||
|
||||
if (!in_array($value, self::$validValues, true)) {
|
||||
$validList = implode(', ', self::$validValues);
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Invalid aria-current value \"{$value}\". Valid values are: {$validList}.",
|
||||
"Set aria-current to one of the valid token values: page, step, location, date, time, true, or false."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaDisabledFocusable extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_DISABLED';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Disabled elements should not have conflicting focusable tabindex settings.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
// 1. Native disabled element with explicit positive/zero tabindex
|
||||
if ($element->hasAttribute('disabled')) {
|
||||
if ($element->hasAttribute('tabindex')) {
|
||||
$tabindex = (int)$element->getAttribute('tabindex');
|
||||
if ($tabindex >= 0) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element has both the 'disabled' attribute and a focusable tabindex=\"{$tabindex}\".",
|
||||
"Remove the tabindex or set tabindex=\"-1\" to avoid keyboard navigation confusion on disabled elements."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Elements with aria-disabled="true" on non-native elements
|
||||
if (strtolower(trim($element->getAttribute('aria-disabled'))) === 'true') {
|
||||
$tagName = strtolower($element->tagName);
|
||||
if (in_array($tagName, ['a', 'button'], true) && $element->hasAttribute('tabindex')) {
|
||||
$tabindex = (int)$element->getAttribute('tabindex');
|
||||
if ($tabindex > 0) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element has aria-disabled=\"true\" with positive tabindex=\"{$tabindex}\".",
|
||||
"Avoid positive tabindex on disabled interactive elements."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaErrorMessage extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_3_3_1_ARIA_ERRORMESSAGE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'aria-errormessage must reference an existing element ID and the element must have aria-invalid set.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (!$element->hasAttribute('aria-errormessage')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$targetId = trim($element->getAttribute('aria-errormessage'));
|
||||
if ($targetId === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Attribute aria-errormessage is empty.",
|
||||
"Provide the ID of an element containing the error message text."
|
||||
);
|
||||
}
|
||||
|
||||
// 1. Verify that target element exists in document
|
||||
$doc = $element->ownerDocument;
|
||||
if ($doc !== null) {
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$targets = $xpath->query('//*[@id="' . $targetId . '"]');
|
||||
if ($targets === false || $targets->length === 0) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Attribute aria-errormessage=\"{$targetId}\" references an ID that does not exist in the document.",
|
||||
"Ensure the referenced error message element ID exists in the HTML document."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Check if element has aria-invalid set to a truthy value (true, grammar, spelling)
|
||||
$ariaInvalid = strtolower(trim($element->getAttribute('aria-invalid')));
|
||||
if ($ariaInvalid === '' || $ariaInvalid === 'false') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element uses aria-errormessage=\"{$targetId}\" but does not have aria-invalid set to \"true\".",
|
||||
"Add aria-invalid=\"true\" to the control when an error message is active."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaLabelMisuseOnGeneric extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_LABEL_GENERIC';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'aria-label or aria-labelledby should not be used on generic <div> or <span> elements without an ARIA role.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$tag = strtolower($element->tagName);
|
||||
if ($tag !== 'div' && $tag !== 'span') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hasRole = $element->hasAttribute('role') && trim($element->getAttribute('role')) !== '';
|
||||
if ($hasRole) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hasAriaLabel = $element->hasAttribute('aria-label') && trim($element->getAttribute('aria-label')) !== '';
|
||||
$hasAriaLabelledby = $element->hasAttribute('aria-labelledby') && trim($element->getAttribute('aria-labelledby')) !== '';
|
||||
|
||||
if ($hasAriaLabel || $hasAriaLabelledby) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Generic <{$tag}> uses aria-label/aria-labelledby without a semantic ARIA role (assistive technologies ignore names on generic elements).",
|
||||
"Add an appropriate ARIA role (e.g. role=\"region\", role=\"group\", role=\"navigation\") or use a semantic HTML5 element."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaProhibitedAttr extends AbstractRule
|
||||
{
|
||||
/** @var array<string, array<int, string>> */
|
||||
private static array $prohibitedAttributesByRole = [
|
||||
'presentation' => ['aria-label', 'aria-labelledby', 'aria-describedby', 'aria-details'],
|
||||
'none' => ['aria-label', 'aria-labelledby', 'aria-describedby', 'aria-details'],
|
||||
'generic' => ['aria-label', 'aria-labelledby', 'aria-roledescription'],
|
||||
'caption' => ['aria-label', 'aria-labelledby']
|
||||
];
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_PROHIBITED_ATTR';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Prohibited ARIA attributes must not be used on roles that do not support naming (e.g. presentation, none).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (!$element->hasAttribute('role')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$roles = explode(' ', strtolower(trim($element->getAttribute('role'))));
|
||||
|
||||
foreach ($roles as $role) {
|
||||
if (isset(self::$prohibitedAttributesByRole[$role])) {
|
||||
$prohibited = self::$prohibitedAttributesByRole[$role];
|
||||
$foundProhibited = [];
|
||||
|
||||
foreach ($prohibited as $attr) {
|
||||
if ($element->hasAttribute($attr)) {
|
||||
$foundProhibited[] = $attr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($foundProhibited)) {
|
||||
$attrList = implode(', ', $foundProhibited);
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element with role=\"{$role}\" contains prohibited ARIA attribute(s): {$attrList}.",
|
||||
"Remove the prohibited attribute(s) or change the element's ARIA role to one that supports naming."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaRedundantRole extends AbstractRule
|
||||
{
|
||||
/** @var array<string, string> */
|
||||
private static array $redundantMap = [
|
||||
'nav' => 'navigation',
|
||||
'main' => 'main',
|
||||
'button' => 'button',
|
||||
'article' => 'article',
|
||||
'aside' => 'complementary',
|
||||
'dialog' => 'dialog',
|
||||
'figure' => 'figure',
|
||||
];
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_REDUNDANT_ROLE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Avoid specifying redundant ARIA roles on HTML elements with identical implicit semantics.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (!$element->hasAttribute('role')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$tagName = strtolower($element->tagName);
|
||||
$role = strtolower(trim($element->getAttribute('role')));
|
||||
|
||||
if (isset(self::$redundantMap[$tagName]) && self::$redundantMap[$tagName] === $role) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Redundant ARIA role=\"{$role}\" on <{$tagName}>. The element natively possesses this implicit semantic role.",
|
||||
"Remove the redundant role=\"{$role}\" attribute (First Rule of ARIA)."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class AriaRoledescription extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_ARIA_ROLEDESCRIPTION';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'aria-roledescription must only be used on elements with a non-generic role and must not be empty.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (!$element->hasAttribute('aria-roledescription')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$desc = trim($element->getAttribute('aria-roledescription'));
|
||||
if ($desc === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Attribute aria-roledescription is empty or contains only whitespace.",
|
||||
"Provide a meaningful description or remove the aria-roledescription attribute."
|
||||
);
|
||||
}
|
||||
|
||||
$role = strtolower(trim($element->getAttribute('role')));
|
||||
if ($role === 'presentation' || $role === 'none' || $role === 'generic') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"aria-roledescription must not be used on elements with role=\"{$role}\".",
|
||||
"Remove aria-roledescription from presentation/generic elements, or provide an appropriate semantic ARIA role."
|
||||
);
|
||||
}
|
||||
|
||||
$tagName = strtolower($element->tagName);
|
||||
if ($role === '' && in_array($tagName, ['div', 'span'], true)) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"aria-roledescription is used on a generic <{$tagName}> element without an explicit ARIA role.",
|
||||
"Add an explicit ARIA role (e.g. role=\"region\", role=\"button\") or use a semantic HTML element."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use DOMXPath;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class ButtonNestedInteractive extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_BUTTON_NESTED_INTERACTIVE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '<button> elements must not contain nested interactive controls.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'button') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$doc = $element->ownerDocument;
|
||||
if ($doc === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
$nestedInteractives = $xpath->query('.//a[@href] | .//button | .//select | .//textarea | .//input[not(@type="hidden")]', $element);
|
||||
|
||||
if ($nestedInteractives !== false && $nestedInteractives->length > 0) {
|
||||
$first = $nestedInteractives->item(0);
|
||||
$nestedTag = $first instanceof DOMElement ? strtolower($first->tagName) : 'interactive element';
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<button> contains a nested interactive <{$nestedTag}> element.",
|
||||
"Remove nested interactive elements from inside the <button> or restructure as sibling elements."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class ColorContrast extends AbstractRule
|
||||
// 1. Parse inline styles (highest priority)
|
||||
$inlineStyle = $element->hasAttribute('style') ? $element->getAttribute('style') : '';
|
||||
$color = $this->parseColorValue($inlineStyle, 'color');
|
||||
$bg = $this->parseColorValue($inlineStyle, 'background-color') ?: $this->parseColorValue($inlineStyle, 'background');
|
||||
$bg = $this->parseColorValue($inlineStyle, 'background-color') ?: $this->parseBackgroundValue($inlineStyle);
|
||||
|
||||
// 2. Fallback: Parse stylesheet styles
|
||||
if (($color === null || $bg === null) && $element->ownerDocument !== null) {
|
||||
@@ -327,6 +327,14 @@ class ColorContrast extends AbstractRule
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parseBackgroundValue(string $style): ?string
|
||||
{
|
||||
if (preg_match('/(?:^|;)\s*background\s*:\s*([^;]+)/i', $style, $matches)) {
|
||||
return $this->extractColorFromBackground(trim($matches[1]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: int, 1: int, 2: int}|null
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use DOMNode;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class DetailsMissingSummary extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_DETAILS_SUMMARY';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '<details> elements must contain a <summary> element to provide an accessible disclosure label.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'details') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hasSummary = false;
|
||||
$summaryEmpty = false;
|
||||
|
||||
foreach ($element->childNodes as $child) {
|
||||
if ($child instanceof DOMElement && strtolower($child->tagName) === 'summary') {
|
||||
$hasSummary = true;
|
||||
$text = trim($child->textContent);
|
||||
$ariaLabel = trim($child->getAttribute('aria-label'));
|
||||
if ($text === '' && $ariaLabel === '') {
|
||||
$summaryEmpty = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasSummary) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<details> element is missing a <summary> element as its label.",
|
||||
"Add a <summary> element with descriptive text as the first child of the <details> tag."
|
||||
);
|
||||
}
|
||||
|
||||
if ($summaryEmpty) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<summary> element inside <details> is empty.",
|
||||
"Provide meaningful text inside the <summary> element to describe the expandable content."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class DraggingMovements extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_2_5_7_DRAGGING_MOVEMENTS';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Elements supporting drag-and-drop operations must provide a single-pointer alternative (WCAG 2.2 SC 2.5.7).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::AA;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$isDraggable = strtolower(trim($element->getAttribute('draggable'))) === 'true';
|
||||
$hasDragEvent = $element->hasAttribute('ondragstart') || $element->hasAttribute('ondrop');
|
||||
|
||||
if (!$isDraggable && !$hasDragEvent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if element or child has alternative buttons/actions or aria-grabbed/keyshortcuts
|
||||
$hasKeyboardShortcut = $element->hasAttribute('aria-keyshortcuts');
|
||||
$hasGrabbed = $element->hasAttribute('aria-grabbed');
|
||||
$hasRole = $element->hasAttribute('role');
|
||||
|
||||
$doc = $element->ownerDocument;
|
||||
$hasButtonsInside = false;
|
||||
if ($doc !== null) {
|
||||
$buttons = $element->getElementsByTagName('button');
|
||||
if ($buttons->length > 0) {
|
||||
$hasButtonsInside = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasKeyboardShortcut && !$hasGrabbed && !$hasButtonsInside) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Draggable element lacks a single-pointer or keyboard-accessible alternative (WCAG 2.2 SC 2.5.7).",
|
||||
"Provide alternative click buttons (e.g. Move Up / Move Down) or keyboard commands for users unable to perform dragging movements."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,16 @@ use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class DuplicateId extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_DUPLICATE_ID';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Element IDs must be unique across the document.';
|
||||
}
|
||||
|
||||
public function check(\DOMDocument $doc): array
|
||||
{
|
||||
$violations = [];
|
||||
@@ -37,7 +47,8 @@ class DuplicateId extends AbstractRule
|
||||
foreach ($elementsWithId as $el) {
|
||||
$violations[] = $this->createViolation(
|
||||
"Duplicate ID \"{$id}\" found. Element ID attribute must be unique across the document.",
|
||||
$el
|
||||
$el,
|
||||
"Change duplicate id=\"{$id}\" to a unique identifier."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +57,18 @@ class DuplicateId extends AbstractRule
|
||||
return $violations;
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||
public function getLevel(): int { return 3; }
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
+95
-12
@@ -3,17 +3,37 @@
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use DOMNode;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class EmptyHeading extends AbstractRule
|
||||
{
|
||||
public function getId(): string { return 'WCAG_1_3_1_EMPTY_HEADING'; }
|
||||
public function getDescription(): string { return 'Heading elements (h1-h6) must have discernible text content.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||
public function getLevel(): int { return 2; }
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_EMPTY_HEADING';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Heading elements (h1-h6) must have discernible text content.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
@@ -26,15 +46,78 @@ class EmptyHeading extends AbstractRule
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. Check direct text content
|
||||
$text = trim($element->textContent);
|
||||
if ($text === '' && !$element->hasAttribute('aria-label') && !$element->hasAttribute('title')) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
$this->getDescription(),
|
||||
'Add descriptive text or an aria-label to the heading element.'
|
||||
);
|
||||
if ($text !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
// 2. Check aria-label
|
||||
if ($element->hasAttribute('aria-label') && trim($element->getAttribute('aria-label')) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. Check title attribute
|
||||
if ($element->hasAttribute('title') && trim($element->getAttribute('title')) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Check aria-labelledby
|
||||
if ($element->hasAttribute('aria-labelledby')) {
|
||||
$id = trim($element->getAttribute('aria-labelledby'));
|
||||
$doc = $element->ownerDocument;
|
||||
if ($id !== '' && $doc !== null) {
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$labels = $xpath->query("//*[@id='$id']");
|
||||
if ($labels !== false && $labels->length > 0) {
|
||||
$labelNode = $labels->item(0);
|
||||
if ($labelNode instanceof DOMNode && trim($labelNode->textContent) !== '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Check img with alt attribute
|
||||
$imgs = $element->getElementsByTagName('img');
|
||||
foreach ($imgs as $img) {
|
||||
if ($img->hasAttribute('alt') && trim($img->getAttribute('alt')) !== '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Check svg with title or aria-label
|
||||
$svgs = $element->getElementsByTagName('svg');
|
||||
foreach ($svgs as $svg) {
|
||||
if ($svg->hasAttribute('aria-label') && trim($svg->getAttribute('aria-label')) !== '') {
|
||||
return null;
|
||||
}
|
||||
$titles = $svg->getElementsByTagName('title');
|
||||
foreach ($titles as $title) {
|
||||
if (trim($title->textContent) !== '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Check element with role="img" and aria-label
|
||||
$doc = $element->ownerDocument;
|
||||
if ($doc !== null) {
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$roleImgs = $xpath->query('.//*[@role="img"]', $element);
|
||||
if ($roleImgs !== false) {
|
||||
foreach ($roleImgs as $roleImg) {
|
||||
if ($roleImg instanceof DOMElement && $roleImg->hasAttribute('aria-label') && trim($roleImg->getAttribute('aria-label')) !== '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
$this->getDescription(),
|
||||
'Add descriptive text, an <img> with alt text, or an aria-label attribute to the heading.'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class FocusNotObscured extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_2_4_11_FOCUS_NOT_OBSCURED';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Fixed, sticky, or overlay elements must not completely obscure keyboard-focused controls (WCAG 2.2 SC 2.4.11).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::AA;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$style = strtolower($element->getAttribute('style'));
|
||||
if (trim($style) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$isFixedOrSticky = str_contains($style, 'position:fixed') || str_contains($style, 'position: fixed') ||
|
||||
str_contains($style, 'position:sticky') || str_contains($style, 'position: sticky');
|
||||
|
||||
if (!$isFixedOrSticky) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if element is a top/bottom bar with high z-index without scroll-padding considerations
|
||||
$hasTopOrBottom = str_contains($style, 'top:0') || str_contains($style, 'top: 0') ||
|
||||
str_contains($style, 'bottom:0') || str_contains($style, 'bottom: 0');
|
||||
|
||||
$hasFullWidth = str_contains($style, 'width:100%') || str_contains($style, 'width: 100%') ||
|
||||
str_contains($style, 'left:0') || str_contains($style, 'left: 0');
|
||||
|
||||
if ($hasTopOrBottom && $hasFullWidth) {
|
||||
// Check if height or z-index is large
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Fixed/sticky header or footer overlay may obscure focused items during keyboard navigation (WCAG 2.2 SC 2.4.11).",
|
||||
"Ensure html/body has adequate scroll-padding-top or scroll-padding-bottom to prevent focused elements from being hidden under sticky bars."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+61
-13
@@ -3,35 +3,56 @@
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use DOMNode;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class FormLabel extends AbstractRule
|
||||
{
|
||||
public function getId(): string { return 'WCAG_1_3_1_LABEL'; }
|
||||
public function getDescription(): string { return 'Form inputs must have an associated label.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||
public function getLevel(): int { return 2; }
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_LABEL';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Form inputs must have an associated label.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$tags = ['input', 'select', 'textarea'];
|
||||
if (!in_array(strtolower($element->tagName), $tags)) {
|
||||
if (!in_array(strtolower($element->tagName), $tags, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Skip hidden inputs and buttons
|
||||
$type = strtolower($element->getAttribute('type'));
|
||||
if ($type === 'hidden' || $type === 'submit' || $type === 'button' || $type === 'reset') {
|
||||
if ($type === 'hidden' || $type === 'submit' || $type === 'button' || $type === 'reset' || $type === 'image') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. Check label for="id"
|
||||
if ($element->hasAttribute('id')) {
|
||||
$id = $element->getAttribute('id');
|
||||
$id = trim($element->getAttribute('id'));
|
||||
$doc = $element->ownerDocument;
|
||||
if ($doc !== null) {
|
||||
if ($id !== '' && $doc !== null) {
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$labels = $xpath->query("//label[@for='$id']");
|
||||
if ($labels !== false && $labels->length > 0) {
|
||||
@@ -40,12 +61,35 @@ class FormLabel extends AbstractRule
|
||||
}
|
||||
}
|
||||
|
||||
// Check for aria-label, aria-labelledby, or title
|
||||
if ($element->hasAttribute('aria-label') || $element->hasAttribute('aria-labelledby') || $element->hasAttribute('title')) {
|
||||
// 2. Check aria-label
|
||||
if ($element->hasAttribute('aria-label') && trim($element->getAttribute('aria-label')) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if wrapped in label
|
||||
// 3. Check aria-labelledby
|
||||
if ($element->hasAttribute('aria-labelledby')) {
|
||||
$ariaLabelledby = trim($element->getAttribute('aria-labelledby'));
|
||||
if ($ariaLabelledby !== '') {
|
||||
$doc = $element->ownerDocument;
|
||||
if ($doc !== null) {
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$ids = array_filter(explode(' ', $ariaLabelledby));
|
||||
foreach ($ids as $targetId) {
|
||||
$targets = $xpath->query("//*[@id='$targetId']");
|
||||
if ($targets !== false && $targets->length > 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Check title attribute
|
||||
if ($element->hasAttribute('title') && trim($element->getAttribute('title')) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 5. Check if wrapped in label
|
||||
$parent = $element->parentNode;
|
||||
while ($parent) {
|
||||
if ($parent instanceof DOMElement && strtolower($parent->tagName) === 'label') {
|
||||
@@ -54,6 +98,10 @@ class FormLabel extends AbstractRule
|
||||
$parent = $parent->parentNode;
|
||||
}
|
||||
|
||||
return $this->createViolation($element, $this->getDescription(), 'Add a <label for="..."> or an aria-label attribute.');
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
$this->getDescription(),
|
||||
'Add a <label for="..."> or an aria-label attribute to associate a label with this input.'
|
||||
);
|
||||
}
|
||||
}
|
||||
+57
-24
@@ -3,39 +3,72 @@
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\AbstractRule;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class HeadingOrder extends AbstractRule
|
||||
{
|
||||
private static int $lastLevel = 0;
|
||||
|
||||
public function getId(): string { return 'WCAG_1_3_1_HEADING'; }
|
||||
public function getDescription(): string { return 'Headings should follow a logical nesting order.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::WARNING; }
|
||||
public function getLevel(): int { return 2; }
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
public function getId(): string
|
||||
{
|
||||
if (!preg_match('/^h([1-6])$/i', $element->tagName, $matches)) {
|
||||
return null;
|
||||
return 'WCAG_1_3_1_HEADING';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Headings should follow a logical nesting order without skipping levels.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(\DOMDocument $doc): array
|
||||
{
|
||||
$violations = [];
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$headings = $xpath->query('//h1 | //h2 | //h3 | //h4 | //h5 | //h6');
|
||||
|
||||
if ($headings === false || $headings->length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$currentLevel = (int)$matches[1];
|
||||
|
||||
// This rule is a bit complex in a per-element check without global state,
|
||||
// but we can at least check if an h2 comes before an h1 in some cases or jumps.
|
||||
// For simplicity in this engine, we warn if it's not starting with H1 or jumps too many levels.
|
||||
|
||||
if ($currentLevel > self::$lastLevel + 1 && self::$lastLevel !== 0) {
|
||||
$violation = $this->createViolation($element, "Heading level h$currentLevel jumps from h" . self::$lastLevel, "Ensure headings follow a logical order (h1, then h2, etc.)");
|
||||
self::$lastLevel = $currentLevel;
|
||||
return $violation;
|
||||
$lastLevel = 0;
|
||||
|
||||
foreach ($headings as $heading) {
|
||||
if (!$heading instanceof DOMElement) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!preg_match('/^h([1-6])$/i', $heading->tagName, $matches)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentLevel = (int)$matches[1];
|
||||
|
||||
// If heading jumps more than 1 level down (e.g. h1 to h3, h2 to h5)
|
||||
if ($lastLevel > 0 && $currentLevel > $lastLevel + 1) {
|
||||
$violations[] = $this->createViolation(
|
||||
"Heading level <h{$currentLevel}> jumps from <h{$lastLevel}>, skipping intermediate heading levels.",
|
||||
$heading,
|
||||
"Ensure headings follow a logical sequence (e.g., <h1> followed by <h2>, not skipping to <h{$currentLevel}>)."
|
||||
);
|
||||
}
|
||||
|
||||
$lastLevel = $currentLevel;
|
||||
}
|
||||
|
||||
self::$lastLevel = $currentLevel;
|
||||
return null;
|
||||
return $violations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class HtmlDirValid extends AbstractRule
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
private static array $validDirValues = ['ltr', 'rtl', 'auto'];
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_2_HTML_DIR';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'The dir attribute must have a valid value (ltr, rtl, or auto).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (!$element->hasAttribute('dir')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$dir = strtolower(trim($element->getAttribute('dir')));
|
||||
|
||||
if (!in_array($dir, self::$validDirValues, true)) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Invalid dir attribute value \"{$dir}\". Valid values are 'ltr', 'rtl', or 'auto'.",
|
||||
"Set dir to \"ltr\", \"rtl\", or \"auto\" for proper bidirectional text handling."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\AbstractRule;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
use YakNet\AccessibilityConsole\Syntax\HtmlSyntaxLinter;
|
||||
|
||||
class HtmlSyntaxValid extends AbstractRule
|
||||
{
|
||||
private HtmlSyntaxLinter $linter;
|
||||
|
||||
public function __construct(?HtmlSyntaxLinter $linter = null)
|
||||
{
|
||||
$this->linter = $linter ?? new HtmlSyntaxLinter();
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_1_HTML_PARSING_SYNTAX';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'HTML documents must be well-formed without duplicate attributes, mismatched tags, or malformed syntax (WCAG 4.1.1).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(\DOMDocument $doc): array
|
||||
{
|
||||
$rawHtml = property_exists($doc, 'rawHtml') && is_string($doc->rawHtml)
|
||||
? $doc->rawHtml
|
||||
: $doc->saveHTML();
|
||||
|
||||
if (empty($rawHtml) || trim($rawHtml) === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$issues = $this->linter->lint($rawHtml);
|
||||
$violations = [];
|
||||
|
||||
foreach ($issues as $issue) {
|
||||
$severity = ($issue->severity === 'warning') ? Severity::WARNING : Severity::ERROR;
|
||||
|
||||
$violations[] = new Violation(
|
||||
ruleId: $this->getId(),
|
||||
message: "[{$issue->code}] {$issue->message}",
|
||||
severity: $severity,
|
||||
standard: $this->getStandard(),
|
||||
htmlSnippet: $issue->snippet,
|
||||
location: [
|
||||
'line' => $issue->line,
|
||||
'column' => $issue->column,
|
||||
],
|
||||
fixSuggestion: $issue->fixSuggestion
|
||||
);
|
||||
}
|
||||
|
||||
return $violations;
|
||||
}
|
||||
}
|
||||
+40
-12
@@ -9,11 +9,30 @@ use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class IframeTitle extends AbstractRule
|
||||
{
|
||||
public function getId(): string { return 'WCAG_4_1_2_IFRAME_TITLE'; }
|
||||
public function getDescription(): string { return 'Iframe elements must have a non-empty title attribute to describe their content.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||
public function getLevel(): int { return 2; }
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_IFRAME_TITLE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Iframe elements must have an accessible name (title or aria-label) to describe their content.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
@@ -21,14 +40,23 @@ class IframeTitle extends AbstractRule
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$element->hasAttribute('title') || trim($element->getAttribute('title')) === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Iframe element is missing a descriptive title attribute.",
|
||||
"Add a descriptive title attribute, e.g., title=\"Embedded Map\" or title=\"Video Player\"."
|
||||
);
|
||||
// Check if decorative / hidden
|
||||
if ($element->getAttribute('aria-hidden') === 'true') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
$title = trim($element->getAttribute('title'));
|
||||
$ariaLabel = trim($element->getAttribute('aria-label'));
|
||||
$ariaLabelledby = trim($element->getAttribute('aria-labelledby'));
|
||||
|
||||
if ($title !== '' || $ariaLabel !== '' || $ariaLabelledby !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Iframe element is missing an accessible title or aria-label attribute.",
|
||||
"Add a descriptive title attribute, e.g., title=\"Embedded Map\" or an aria-label."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class InputAutocompleteAppropriate extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_5_AUTOCOMPLETE_APPROPRIATE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Input autocomplete value must be semantically appropriate for the input type (WCAG 1.3.5).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::AA;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'input') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$element->hasAttribute('autocomplete')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = strtolower($element->getAttribute('type') ?: 'text');
|
||||
$autocomplete = strtolower(trim($element->getAttribute('autocomplete')));
|
||||
|
||||
if ($autocomplete === '' || in_array($autocomplete, ['on', 'off'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Email type should not have telephone or postal autocomplete
|
||||
if ($type === 'email' && (str_contains($autocomplete, 'tel') || str_contains($autocomplete, 'postal') || str_contains($autocomplete, 'bday'))) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Inappropriate autocomplete=\"{$autocomplete}\" on <input type=\"email\">.",
|
||||
"Use autocomplete=\"email\" or \"username\" for email inputs."
|
||||
);
|
||||
}
|
||||
|
||||
// Number type should not have name, street-address, or email
|
||||
if ($type === 'number' && (str_contains($autocomplete, 'name') || str_contains($autocomplete, 'email') || str_contains($autocomplete, 'address') || str_contains($autocomplete, 'country'))) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Inappropriate autocomplete=\"{$autocomplete}\" on <input type=\"number\">.",
|
||||
"Number inputs should use numeric autocomplete tokens like \"bday-year\", \"cc-exp-year\", or \"tel\"."
|
||||
);
|
||||
}
|
||||
|
||||
// Checkbox or Radio should not have email or password autocompletes
|
||||
if (in_array($type, ['checkbox', 'radio'], true) && (str_contains($autocomplete, 'password') || str_contains($autocomplete, 'email'))) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Inappropriate autocomplete=\"{$autocomplete}\" on <input type=\"{$type}\">.",
|
||||
"Do not apply credential or text autocompletes to checkbox/radio inputs."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,30 @@ use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class InputMissingAutocomplete extends AbstractRule
|
||||
{
|
||||
public function getId(): string { return 'WCAG_1_3_5_INPUT_AUTOCOMPLETE'; }
|
||||
public function getDescription(): string { return 'Input fields collecting personal data should have an autocomplete attribute.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::AA; }
|
||||
public function getSeverity(): Severity { return Severity::WARNING; }
|
||||
public function getLevel(): int { return 3; }
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_3_3_8_ACCESSIBLE_AUTH';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Authentication inputs must support password managers and must not disable autocomplete or paste (WCAG 2.2 SC 3.3.8).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::AA;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
@@ -22,32 +41,37 @@ class InputMissingAutocomplete extends AbstractRule
|
||||
}
|
||||
|
||||
$type = strtolower($element->getAttribute('type'));
|
||||
if (in_array($type, ['hidden', 'submit', 'button', 'reset', 'checkbox', 'radio', 'image', 'file'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = strtolower($element->getAttribute('name'));
|
||||
$id = strtolower($element->getAttribute('id'));
|
||||
$targetKeywords = ['email', 'phone', 'tel', 'username', 'user', 'password', 'pass', 'address', 'zip', 'city', 'country', 'name', 'fname', 'lname'];
|
||||
|
||||
$isPersonalField = false;
|
||||
if (in_array($type, ['email', 'tel'], true)) {
|
||||
$isPersonalField = true;
|
||||
} else {
|
||||
foreach ($targetKeywords as $keyword) {
|
||||
if (str_contains($name, $keyword) || str_contains($id, $keyword)) {
|
||||
$isPersonalField = true;
|
||||
break;
|
||||
}
|
||||
// 1. Check for paste blocking on input fields (which harms accessible authentication)
|
||||
if ($element->hasAttribute('onpaste')) {
|
||||
$onpaste = strtolower(trim($element->getAttribute('onpaste')));
|
||||
if (str_contains($onpaste, 'return false') || str_contains($onpaste, 'preventdefault')) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Input field blocks pasting (onpaste handler). This violates accessible authentication (WCAG 2.2 SC 3.3.8).",
|
||||
"Remove paste restrictions so users can paste credentials from password managers."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($isPersonalField && (!$element->hasAttribute('autocomplete') || trim($element->getAttribute('autocomplete')) === '')) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
$this->getDescription(),
|
||||
'Add an autocomplete attribute (e.g., autocomplete="email", autocomplete="username") to improve accessibility and user experience.'
|
||||
);
|
||||
// 2. Password fields should not have autocomplete="off"
|
||||
if ($type === 'password') {
|
||||
$autocomplete = strtolower(trim($element->getAttribute('autocomplete')));
|
||||
if ($autocomplete === 'off') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Password input has autocomplete=\"off\", preventing password managers from assisting users.",
|
||||
"Change autocomplete to \"current-password\" or \"new-password\" instead of \"off\"."
|
||||
);
|
||||
}
|
||||
|
||||
if ($autocomplete === '' && !$element->hasAttribute('autocomplete')) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Password input should specify autocomplete=\"current-password\" or autocomplete=\"new-password\".",
|
||||
"Add autocomplete=\"current-password\" (for login) or autocomplete=\"new-password\" (for registration/reset)."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class MediaControls extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_4_2_MEDIA_CONTROLS';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Audio and video elements should provide controls for user interaction.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$tag = strtolower($element->tagName);
|
||||
if ($tag !== 'audio' && $tag !== 'video') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if controls attribute is present
|
||||
if ($element->hasAttribute('controls')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Allow background video if explicitly muted and looping
|
||||
$isMuted = $element->hasAttribute('muted');
|
||||
$isAutoplay = $element->hasAttribute('autoplay');
|
||||
$isLoop = $element->hasAttribute('loop');
|
||||
|
||||
if ($tag === 'video' && $isMuted && $isAutoplay && $isLoop) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<{$tag}> element is missing the 'controls' attribute.",
|
||||
"Add the 'controls' attribute to allow users to play, pause, and adjust media volume."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\AbstractRule;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class MetaCharsetPresent extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_3_1_1_META_CHARSET';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'HTML documents should specify character encoding (meta charset) inside the <head> element.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(\DOMDocument $doc): array
|
||||
{
|
||||
$heads = $doc->getElementsByTagName('head');
|
||||
if ($heads->length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$head = $heads->item(0);
|
||||
if (!$head instanceof DOMElement) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$hasCharset = false;
|
||||
$metas = $head->getElementsByTagName('meta');
|
||||
|
||||
foreach ($metas as $meta) {
|
||||
if ($meta->hasAttribute('charset') && trim($meta->getAttribute('charset')) !== '') {
|
||||
$hasCharset = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (strtolower($meta->getAttribute('http-equiv')) === 'content-type') {
|
||||
$content = strtolower($meta->getAttribute('content'));
|
||||
if (str_contains($content, 'charset=')) {
|
||||
$hasCharset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasCharset) {
|
||||
return [
|
||||
$this->createViolation(
|
||||
"The document <head> is missing a character encoding declaration (<meta charset=\"utf-8\">).",
|
||||
$head,
|
||||
"Add <meta charset=\"utf-8\"> as the first child of the <head> tag to prevent screen reader character misinterpretations."
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class MeterAccessibility extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_METER_ACCESSIBLE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '<meter> elements must have an accessible name and valid values.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'meter') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. Check for accessible name
|
||||
$hasName = false;
|
||||
|
||||
if ($element->hasAttribute('aria-label') && trim($element->getAttribute('aria-label')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif ($element->hasAttribute('aria-labelledby') && trim($element->getAttribute('aria-labelledby')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif ($element->hasAttribute('title') && trim($element->getAttribute('title')) !== '') {
|
||||
$hasName = true;
|
||||
} elseif ($element->hasAttribute('id')) {
|
||||
$id = trim($element->getAttribute('id'));
|
||||
$doc = $element->ownerDocument;
|
||||
if ($id !== '' && $doc !== null) {
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$labels = $xpath->query("//label[@for='{$id}']");
|
||||
if ($labels !== false && $labels->length > 0) {
|
||||
$hasName = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasName) {
|
||||
// Check if wrapped in <label>
|
||||
$parent = $element->parentNode;
|
||||
while ($parent) {
|
||||
if ($parent instanceof DOMElement && strtolower($parent->tagName) === 'label') {
|
||||
$hasName = true;
|
||||
break;
|
||||
}
|
||||
$parent = $parent->parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasName) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<meter> element is missing an accessible name.",
|
||||
"Add an aria-label, title, or associated <label> element to describe the gauge value."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -10,16 +10,35 @@ use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class NestedInteractive extends AbstractRule
|
||||
{
|
||||
public function getId(): string { return 'WCAG_4_1_2_NestedInteractive'; }
|
||||
public function getDescription(): string { return 'Checks for nested interactive elements.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||
public function getLevel(): int { return 3; }
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_4_1_2_NESTED_INTERACTIVE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Interactive elements (<a>, <button>, etc.) must not contain nested interactive controls.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$tag = strtolower($element->tagName);
|
||||
if (!in_array($tag, ['a', 'button'])) {
|
||||
if (!in_array($tag, ['a', 'button'], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -27,14 +46,17 @@ class NestedInteractive extends AbstractRule
|
||||
if ($doc === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
$interactives = $xpath->query('.//a | .//button | .//input | .//select | .//textarea', $element);
|
||||
$interactives = $xpath->query('.//a[@href] | .//button | .//select | .//textarea | .//input[not(@type="hidden")]', $element);
|
||||
|
||||
if ($interactives !== false && $interactives->length > 0) {
|
||||
$first = $interactives->item(0);
|
||||
$nestedTag = $first instanceof DOMElement ? strtolower($first->tagName) : 'interactive';
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"İç içe geçmiş etkileşimli öğeler bulundu (<{$tag}> içerisinde).",
|
||||
'Ensure interactive controls are not nested.'
|
||||
"Nested interactive control <{$nestedTag}> found inside <{$tag}>.",
|
||||
"Ensure interactive controls are not nested inside each other."
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+26
-21
@@ -9,11 +9,30 @@ use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class PageTitle extends AbstractRule
|
||||
{
|
||||
public function getId(): string { return 'WCAG_2_4_2_PAGE_TITLE'; }
|
||||
public function getDescription(): string { return 'Web pages must have a non-empty title element in the head.'; }
|
||||
public function getStandard(): WCAGStandard { return WCAGStandard::A; }
|
||||
public function getSeverity(): Severity { return Severity::ERROR; }
|
||||
public function getLevel(): int { return 1; }
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_2_4_2_PAGE_TITLE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Web pages must have a <title> element inside the <head>.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
@@ -26,22 +45,8 @@ class PageTitle extends AbstractRule
|
||||
if ($titles->length === 0) {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
$this->getDescription(),
|
||||
'Add a <title> element inside the <head>.'
|
||||
);
|
||||
}
|
||||
|
||||
$titleText = '';
|
||||
$firstTitle = $titles->item(0);
|
||||
if ($firstTitle !== null) {
|
||||
$titleText = trim($firstTitle->textContent);
|
||||
}
|
||||
|
||||
if ($titleText === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
$this->getDescription(),
|
||||
'Provide descriptive text inside the <title> element.'
|
||||
"The <head> element is missing a <title> element.",
|
||||
'Add a <title> element inside the <head> to provide a page title.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class RoleImgAlt extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_1_1_ROLE_IMG';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Elements with role="img" must have an accessible text alternative.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) === 'img') {
|
||||
return null; // Handled by ImgAltText
|
||||
}
|
||||
|
||||
$roles = explode(' ', strtolower(trim($element->getAttribute('role'))));
|
||||
if (!in_array('img', $roles, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($element->getAttribute('aria-hidden') === 'true') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ariaLabel = trim($element->getAttribute('aria-label'));
|
||||
$ariaLabelledby = trim($element->getAttribute('aria-labelledby'));
|
||||
$title = trim($element->getAttribute('title'));
|
||||
$text = trim($element->textContent);
|
||||
|
||||
if ($ariaLabel !== '' || $ariaLabelledby !== '' || $title !== '' || $text !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Element with role=\"img\" (<{$element->tagName}>) does not have an accessible name.",
|
||||
"Provide an accessible description using aria-label, aria-labelledby, or title, or hide it if decorative using aria-hidden=\"true\"."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class SelectValidChildren extends AbstractRule
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
private static array $validChildTags = ['option', 'optgroup', 'script', 'template', 'hr'];
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_SELECT_CHILDREN';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '<select> elements must only contain valid child elements (<option>, <optgroup>, <script>, <template>).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'select') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$invalidTags = [];
|
||||
|
||||
foreach ($element->childNodes as $child) {
|
||||
if ($child instanceof DOMElement) {
|
||||
$childTag = strtolower($child->tagName);
|
||||
if (!in_array($childTag, self::$validChildTags, true)) {
|
||||
$invalidTags[] = "<{$childTag}>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($invalidTags)) {
|
||||
$invalidStr = implode(', ', array_unique($invalidTags));
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<select> contains invalid direct child elements: {$invalidStr}.",
|
||||
"Remove non-option elements from the <select> or restructure using <optgroup> and <option> tags."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@ class StrictRuleSet extends RuleEngine
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->addRule(new ImageAltRule());
|
||||
$this->addRule(new HeadingOrderRule());
|
||||
$this->addRule(new EmptyLinkRule());
|
||||
// Daha fazla kural buraya eklenebilir
|
||||
$rules = RuleLevels::getRulesForLevel(5);
|
||||
foreach ($rules as $rule) {
|
||||
$this->addRule($rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class TableHeaderNotEmpty extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_TH_NOT_EMPTY';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '<th> table header cells must have discernible text or an accessible name.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'th') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$html = $element->ownerDocument ? $element->ownerDocument->saveHTML($element) : '';
|
||||
if ($html !== false && preg_match('/<\?php|\{\{|\{%/i', $html)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. Text content
|
||||
if (trim($element->textContent) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. aria-label or title
|
||||
if ($element->hasAttribute('aria-label') && trim($element->getAttribute('aria-label')) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($element->hasAttribute('title') && trim($element->getAttribute('title')) !== '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. Img with alt
|
||||
$imgs = $element->getElementsByTagName('img');
|
||||
foreach ($imgs as $img) {
|
||||
if ($img->hasAttribute('alt') && trim($img->getAttribute('alt')) !== '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Svg with title or aria-label
|
||||
$svgs = $element->getElementsByTagName('svg');
|
||||
foreach ($svgs as $svg) {
|
||||
if ($svg->hasAttribute('aria-label') && trim($svg->getAttribute('aria-label')) !== '') {
|
||||
return null;
|
||||
}
|
||||
$titles = $svg->getElementsByTagName('title');
|
||||
foreach ($titles as $title) {
|
||||
if (trim($title->textContent) !== '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Table header cell <th> is empty and has no accessible name.",
|
||||
"Add meaningful text content or an aria-label to describe the column or row represented by this <th>."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class TableHeadersAttributeValid extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_3_1_TABLE_HEADERS_ATTR';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'The headers attribute on table cells must refer to valid <th> elements within the same table.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$tag = strtolower($element->tagName);
|
||||
if ($tag !== 'td' && $tag !== 'th') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$element->hasAttribute('headers')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$headersStr = trim($element->getAttribute('headers'));
|
||||
if ($headersStr === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Empty 'headers' attribute found on <{$tag}>.",
|
||||
"Provide space-separated IDs of the corresponding <th> header cells or remove the empty attribute."
|
||||
);
|
||||
}
|
||||
|
||||
// Find enclosing table
|
||||
$table = $element->parentNode;
|
||||
while ($table !== null && (!($table instanceof DOMElement) || strtolower($table->tagName) !== 'table')) {
|
||||
$table = $table->parentNode;
|
||||
}
|
||||
|
||||
if (!$table instanceof DOMElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$headerIds = array_filter(explode(' ', $headersStr));
|
||||
$invalidIds = [];
|
||||
|
||||
$doc = $element->ownerDocument;
|
||||
if ($doc === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$xpath = new \DOMXPath($doc);
|
||||
|
||||
foreach ($headerIds as $hid) {
|
||||
$matchingTh = $xpath->query(".//th[@id='{$hid}']", $table);
|
||||
if ($matchingTh === false || $matchingTh->length === 0) {
|
||||
$invalidIds[] = $hid;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($invalidIds)) {
|
||||
$invalidStr = implode(', ', $invalidIds);
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"The headers attribute refers to ID(s) not found as <th> elements within the table: {$invalidStr}.",
|
||||
"Ensure each ID specified in the 'headers' attribute matches the 'id' of a <th> element in this table."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class TargetSizeMinimum extends AbstractRule
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_2_5_8_TARGET_SIZE';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Interactive elements must have a minimum target size of at least 24x24 CSS pixels (WCAG 2.2).';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::AA;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::WARNING;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
$tagName = strtolower($element->tagName);
|
||||
$isInteractive = false;
|
||||
|
||||
if ($tagName === 'a' && $element->hasAttribute('href')) {
|
||||
$isInteractive = true;
|
||||
} elseif (in_array($tagName, ['button', 'select', 'textarea'], true)) {
|
||||
$isInteractive = true;
|
||||
} elseif ($tagName === 'input') {
|
||||
$type = strtolower($element->getAttribute('type'));
|
||||
if ($type !== 'hidden') {
|
||||
$isInteractive = true;
|
||||
}
|
||||
} elseif ($element->hasAttribute('role')) {
|
||||
$role = strtolower(trim($element->getAttribute('role')));
|
||||
if (in_array($role, ['button', 'link', 'checkbox', 'radio', 'tab', 'menuitem'], true)) {
|
||||
$isInteractive = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isInteractive) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$style = $element->getAttribute('style');
|
||||
if (trim($style) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$width = $this->parsePixelDimension($style, 'width');
|
||||
$height = $this->parsePixelDimension($style, 'height');
|
||||
|
||||
$tooSmallWidth = ($width !== null && $width < 24.0);
|
||||
$tooSmallHeight = ($height !== null && $height < 24.0);
|
||||
|
||||
if ($tooSmallWidth || $tooSmallHeight) {
|
||||
$wStr = $width !== null ? "{$width}px" : "auto";
|
||||
$hStr = $height !== null ? "{$height}px" : "auto";
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Interactive element target size ({$wStr} x {$hStr}) is smaller than the required 24x24px minimum (WCAG 2.2 SC 2.5.8).",
|
||||
"Ensure interactive targets have a minimum width and height of at least 24x24px, or add adequate spacing/padding around them."
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function parsePixelDimension(string $style, string $prop): ?float
|
||||
{
|
||||
if (preg_match('/(?:^|;)\s*' . preg_quote($prop, '/') . '\s*:\s*([0-9.]+)\s*px/i', $style, $matches)) {
|
||||
return (float)$matches[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace YakNet\AccessibilityConsole\Rules;
|
||||
|
||||
use DOMElement;
|
||||
use YakNet\AccessibilityConsole\Core\Severity;
|
||||
use YakNet\AccessibilityConsole\Core\Violation;
|
||||
use YakNet\AccessibilityConsole\Core\WCAGStandard;
|
||||
|
||||
class TrackValidation extends AbstractRule
|
||||
{
|
||||
/** @var array<int, string> */
|
||||
private static array $validKinds = ['subtitles', 'captions', 'descriptions', 'chapters', 'metadata'];
|
||||
|
||||
public function getId(): string
|
||||
{
|
||||
return 'WCAG_1_2_2_TRACK_VALIDATION';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '<track> elements must specify a valid kind, and captions/subtitles must include srclang and label.';
|
||||
}
|
||||
|
||||
public function getStandard(): WCAGStandard
|
||||
{
|
||||
return WCAGStandard::A;
|
||||
}
|
||||
|
||||
public function getSeverity(): Severity
|
||||
{
|
||||
return Severity::ERROR;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function check(DOMElement $element): ?Violation
|
||||
{
|
||||
if (strtolower($element->tagName) !== 'track') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 1. Kind attribute validity
|
||||
$kind = strtolower(trim($element->getAttribute('kind')));
|
||||
if ($kind !== '' && !in_array($kind, self::$validKinds, true)) {
|
||||
$validList = implode(', ', self::$validKinds);
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"Invalid track kind \"{$kind}\". Valid values are: {$validList}.",
|
||||
"Set kind to one of: subtitles, captions, descriptions, chapters, metadata."
|
||||
);
|
||||
}
|
||||
|
||||
// Default kind if omitted is 'subtitles'
|
||||
$effectiveKind = $kind !== '' ? $kind : 'subtitles';
|
||||
|
||||
// 2. If captions or subtitles, check srclang and label
|
||||
if (in_array($effectiveKind, ['captions', 'subtitles'], true)) {
|
||||
$srclang = trim($element->getAttribute('srclang'));
|
||||
$label = trim($element->getAttribute('label'));
|
||||
|
||||
if ($srclang === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<track kind=\"{$effectiveKind}\"> element is missing the required 'srclang' attribute.",
|
||||
"Add a valid BCP 47 language code (e.g. srclang=\"en\" or srclang=\"tr\")."
|
||||
);
|
||||
}
|
||||
|
||||
if ($label === '') {
|
||||
return $this->createViolation(
|
||||
$element,
|
||||
"<track kind=\"{$effectiveKind}\"> element is missing the required 'label' attribute.",
|
||||
"Add a human-readable title (e.g. label=\"English Captions\" or label=\"Türkçe Altyazı\")."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user