22 protected $file_pattern =
'~\.(?:php|js|css|xml|json|yml|txt|rst|md|gitignore|htaccess|mailmap|sh)$~';
41 $this->substr_start = strlen($this->
normalizePath($root)) + 1;
47 $key = substr($file, $this->substr_start);
50 $errors =
$report[self::KEY_REMAINING];
51 array_splice($errors, count($errors), 0,
$report[self::KEY_CORRECTIONS]);
56 if (
$report[self::KEY_NEW_CONTENT] !== null) {
57 file_put_contents($file,
$report[self::KEY_NEW_CONTENT]);
59 if (
$report[self::KEY_REMAINING]) {
62 if (
$report[self::KEY_CORRECTIONS]) {
79 $this->substr_start = strlen($this->
normalizePath($root)) + 1;
98 $content = file_get_contents($filepath);
104 self::KEY_REMAINING => array(),
105 self::KEY_CORRECTIONS => array(),
106 self::KEY_NEW_CONTENT => null,
110 $new = preg_replace(
'~(\S)[ \t]+(\r?\n)~',
'$1$2', $old, -1,
$count);
112 $return[self::KEY_CORRECTIONS][] =
"line(s) with trailing whitespace ($count)";
116 if (!preg_match(
'~\.(?:rst|md)$~', $filepath)) {
120 $return[self::KEY_CORRECTIONS][] =
"empty line(s) with whitespace ($count)";
124 if (pathinfo($filepath, PATHINFO_EXTENSION) ===
'php') {
128 $return[self::KEY_CORRECTIONS][] =
'unnecessary close PHP tag';
150 while (
false !== ($entry = $d->read())) {
151 if ($entry ===
'.' || $entry ===
'..') {
156 $relative_path = substr($full, $this->substr_start);
159 if ($entry[0] ===
'.' || preg_match(
'~(?:/vendors?)$~', $full)) {
161 if ($entry !==
'.scripts') {
166 if (in_array($relative_path, array(
'node_modules',
'docs/_build'))) {
174 if (basename($dir) ===
'languages' && $entry !==
'en.php') {
178 if ($relative_path ===
'install/config/htaccess.dist' || preg_match($this->file_pattern, $entry)) {
195 return str_replace(
'\\',
'/', rtrim(
$path,
'/\\'));
if(!array_key_exists($filename, $text_files)) $file
findFilesToAnalyze($root)
Find files which can be analyzed/fixed by this component.
analyzeFile($filepath, $content=null)
Analyze a file for problems and return a report.
normalizePath($path)
Normalize a path.
$content
Set robots.txt action.
findFiles($dir, &$files)
Find files within a directory (recurse for subdirectories)
fixDirectory($root, $dry_run=false)
Fix problems in a directory of files and return a report.
foreach($resources as $id=> $href) if(!empty($resources_html)) $files