This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathphp_recursive_lint.php
93 lines (77 loc) · 2.03 KB
/
php_recursive_lint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Author: NewEraCracker
* License: Public Domain
* Version: 2016.0108.1
*/
# Basic configuration
define('PHP_EXE_PATH', 'C:/WherePHPis/php.exe');
$path = './';
$php_types = array('php','inc');
/** Array with the paths a dir contains */
function readdir_recursive($dir='.', $show_dirs=false, $ignored=array())
{
// Set types for stack and return value
$stack = $result = array();
// Initialize stack
$stack[] = $dir;
// Pop the first element of stack and evaluate it (do this until stack is fully empty)
while($dir = array_shift($stack))
{
$dh = opendir($dir);
while($dh && (false !== ($path = readdir($dh))))
{
if($path != '.' && $path != '..')
{
// Prepend dir to current path
$path = $dir.'/'.$path;
if(is_dir($path))
{
// Check ignored dirs
if(is_array($ignored) && count($ignored) && in_array($path.'/', $ignored))
continue;
// Add dir to stack for reading
$stack[] = $path;
// If $show_dirs is true, add dir path to result
if($show_dirs)
$result[] = $path;
}
elseif(is_file($path))
{
// Check ignored files
if(is_array($ignored) && count($ignored) && in_array($path, $ignored))
continue;
// Add file path to result
$result[] = $path;
}
}
}
closedir($dh);
}
// Sort the array using simple ordering
sort($result);
// Now we can return it
return $result;
}
if(isset($_SERVER['REQUEST_METHOD']) || !isset($_SERVER['argc']) || !isset($_SERVER['argv']))
{
// We are not in CLI - Send header to set our content as plain text
header('Content-Type: text/plain');
}
// Check
if(!is_executable(PHP_EXE_PATH))
exit('PHP executable not found.');
if(!is_dir($path) || !is_readable($path) || !is_writable($path))
exit($path.' is invalid');
// Fix
$path = rtrim($path, '/');
foreach(readdir_recursive($path) as $file)
{
// Grab extension
$ext = pathinfo($file, PATHINFO_EXTENSION);
// Check and execute lint
if(in_array($ext, $php_types))
{
passthru(escapeshellarg(PHP_EXE_PATH).' -n -l '.escapeshellarg($file));
}
}