1<?php declare(strict_types=1); 2 3namespace PhpParser; 4 5require __DIR__ . '/../vendor/autoload.php'; 6 7function canonicalize($str) { 8 // normalize EOL style 9 $str = str_replace("\r\n", "\n", $str); 10 11 // trim newlines at end 12 $str = rtrim($str, "\n"); 13 14 // remove trailing whitespace on all lines 15 $lines = explode("\n", $str); 16 $lines = array_map(function ($line) { 17 return rtrim($line, " \t"); 18 }, $lines); 19 return implode("\n", $lines); 20} 21 22function filesInDir($directory, $fileExtension) { 23 $directory = realpath($directory); 24 $it = new \RecursiveDirectoryIterator($directory); 25 $it = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::LEAVES_ONLY); 26 $it = new \RegexIterator($it, '(\.' . preg_quote($fileExtension) . '$)'); 27 foreach ($it as $file) { 28 $fileName = $file->getPathname(); 29 yield $fileName => file_get_contents($fileName); 30 } 31} 32