phpFilesIn($viewDir); $this->assertGreaterThan(0, count($files), 'src/Views enthält PHP-Dateien'); $styleCount = 0; $handlerFiles = []; foreach ($files as $file) { $content = file_get_contents($file); if ($content === false) { continue; } $styleCount += substr_count($content, 'style="'); if (preg_match('/\bon(click|change|input)=/', $content)) { $handlerFiles[] = substr($file, strlen($viewDir) + 1); } } $this->assert( $styleCount <= self::STYLE_BUDGET, "style=\"-Vorkommen unter src/Views bleiben im Budget (erhalten: $styleCount, Budget: " . self::STYLE_BUDGET . ')' ); $this->assert( $handlerFiles === [], 'Keine onclick=/onchange=/oninput=-Attribute mehr in src/Views (gefunden in: ' . implode(', ', $handlerFiles) . ')' ); } /** @return string[] */ private function phpFilesIn(string $dir): array { $files = []; $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS)); foreach ($it as $fileInfo) { if ($fileInfo->isFile() && $fileInfo->getExtension() === 'php') { $files[] = $fileInfo->getPathname(); } } return $files; } }