New Branch Structure
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Stylist\Services;
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Modules\Stylist\Theme\Theme;
|
||||
|
||||
final class ThemeAccessibilityValidator
|
||||
{
|
||||
public function __construct(private readonly Filesystem $files) {}
|
||||
|
||||
/** @return array<int, array{severity:string,message:string,file:string}> */
|
||||
public function validate(Theme $theme): array
|
||||
{
|
||||
$issues = [];
|
||||
foreach ($this->files->allFiles($theme->path().'/views') as $file) {
|
||||
$content = $file->getContents();
|
||||
$relative = $file->getRelativePathname();
|
||||
if (preg_match_all('/<img\b(?![^>]*\balt=)[^>]*>/i', $content, $matches)) {
|
||||
$issues[] = ['severity' => 'error', 'message' => count($matches[0]).' image(s) missing alt text.', 'file' => $relative];
|
||||
}
|
||||
if (preg_match('/<html\b(?![^>]*\blang=)/i', $content)) {
|
||||
$issues[] = ['severity' => 'warning', 'message' => 'HTML element is missing a lang attribute.', 'file' => $relative];
|
||||
}
|
||||
if (preg_match_all('/<button\b[^>]*>\s*(?:<[^>]+>\s*)*<\/button>/is', $content, $matches)) {
|
||||
$issues[] = ['severity' => 'warning', 'message' => count($matches[0]).' button(s) may lack an accessible name.', 'file' => $relative];
|
||||
}
|
||||
}
|
||||
return $issues;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user