diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..6e451fa --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 6 + paths: + - src diff --git a/src/Console/Command/ScanCommand.php b/src/Console/Command/ScanCommand.php index 5aff13e..30b6408 100644 --- a/src/Console/Command/ScanCommand.php +++ b/src/Console/Command/ScanCommand.php @@ -16,7 +16,7 @@ use YakNet\AccessibilityConsole\Source\SourceLocator; class ScanCommand extends Command { - protected static $defaultName = 'scan'; + protected static ?string $defaultName = 'scan'; protected function configure(): void { diff --git a/src/Core/Config.php b/src/Core/Config.php index 7d59000..a115afe 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -4,8 +4,12 @@ namespace YakNet\AccessibilityConsole\Core; class Config { + /** @var array */ private array $settings = []; + /** + * @param array $settings + */ public function __construct(array $settings = []) { $this->settings = $settings; diff --git a/src/Core/RuleEngine.php b/src/Core/RuleEngine.php index cf4c0aa..f2dc10a 100644 --- a/src/Core/RuleEngine.php +++ b/src/Core/RuleEngine.php @@ -4,7 +4,7 @@ namespace YakNet\AccessibilityConsole\Core; class RuleEngine { - /** @var array */ + /** @var array */ private array $rules = []; public function addRule(mixed $rule): void diff --git a/src/Core/Violation.php b/src/Core/Violation.php index 2690ee1..e3739f7 100644 --- a/src/Core/Violation.php +++ b/src/Core/Violation.php @@ -4,6 +4,9 @@ namespace YakNet\AccessibilityConsole\Core; class Violation { + /** + * @param array{file: string, line: int}|null $location + */ public function __construct( public string $ruleId, public string $message, @@ -14,6 +17,9 @@ class Violation public ?string $fixSuggestion = null ) {} + /** + * @return array{ruleId: string, message: string, severity: string, standard: string, htmlSnippet: string, location: array{file: string, line: int}|null, fixSuggestion: string|null} + */ public function toArray(): array { return [ diff --git a/src/Rules/AriaRole.php b/src/Rules/AriaRole.php index 40b2110..5c7134b 100644 --- a/src/Rules/AriaRole.php +++ b/src/Rules/AriaRole.php @@ -8,6 +8,7 @@ use YakNet\AccessibilityConsole\Core\WCAGStandard; class AriaRole extends AbstractRule { + /** @var array */ private static array $validRoles = [ 'alert', 'alertdialog', 'application', 'article', 'banner', 'button', 'cell', 'checkbox', 'columnheader', 'combobox', 'complementary', 'contentinfo', 'definition', 'dialog', 'directory', diff --git a/src/Rules/ColorContrast.php b/src/Rules/ColorContrast.php index 008b95b..e1f227b 100644 --- a/src/Rules/ColorContrast.php +++ b/src/Rules/ColorContrast.php @@ -92,6 +92,9 @@ class ColorContrast extends AbstractRule return null; } + /** + * @return array{0: int, 1: int, 2: int}|null + */ private function hexToRgb(string $hex): ?array { $hex = ltrim($hex, '#'); diff --git a/src/Source/SourceLocator.php b/src/Source/SourceLocator.php index cbbb59e..11c01a3 100644 --- a/src/Source/SourceLocator.php +++ b/src/Source/SourceLocator.php @@ -8,12 +8,16 @@ use SplFileInfo; class SourceLocator { + /** @var array */ private array $extensions = ['php', 'html', 'twig', 'blade.php']; public function __construct( private readonly string $searchPath ) {} + /** + * @return array{file: string, line: int}|null + */ public function locate(string $snippet): ?array { if (!is_dir($this->searchPath) || !is_readable($this->searchPath)) { @@ -76,6 +80,9 @@ class SourceLocator return false; } + /** + * @return array{type: string, score?: float, location?: array{file: string, line: int}} + */ private function searchInFile(string $filepath, string $searchSnippet, string $fullSnippet): array { $content = file_get_contents($filepath); @@ -118,6 +125,9 @@ class SourceLocator return ['type' => 'none']; } + /** + * @return array{tag: string|null, attributes: array} + */ private function parseSnippet(string $snippet): array { preg_match('/<([a-zA-Z0-9]+)/', $snippet, $matches); @@ -133,6 +143,9 @@ class SourceLocator return ['tag' => $tagName, 'attributes' => $attributes]; } + /** + * @param array{tag: string|null, attributes: array} $parsed + */ private function calculateFuzzyScore(string $line, array $parsed): float { if (!$parsed['tag'] || !str_contains(strtolower($line), '<' . strtolower($parsed['tag']))) {