-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplinter
More file actions
executable file
·144 lines (128 loc) · 4.03 KB
/
plinter
File metadata and controls
executable file
·144 lines (128 loc) · 4.03 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env php
<?php
// Executable CLI entrypoint for plinter. Delegates to Plinter\Runner.
if (php_sapi_name() !== 'cli') {
return;
}
// Prefer Composer autoload when available
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
} else {
require_once __DIR__ . '/src/Runner.php';
}
use Plinter\Runner;
$runner = new Runner();
// Parse CLI args
$args = $argv;
array_shift($args); // drop script name
$skipVendor = false;
$verbose = false;
$explicitArgs = [];
foreach ($args as $arg) {
if ($arg === '--skip-vendor') {
$skipVendor = true;
continue;
}
if ($arg === '--verbose' || $arg === '-v') {
$verbose = true;
continue;
}
$explicitArgs[] = $arg;
}
$directoriesToScan = null;
if (!empty($explicitArgs)) {
$dirs = [];
foreach ($explicitArgs as $a) {
foreach (array_map('trim', explode(',', $a)) as $part) {
if ($part === '') continue;
if (strpos($part, DIRECTORY_SEPARATOR) === 0) {
$full = $part;
} else {
$full = realpath(getcwd() . DIRECTORY_SEPARATOR . $part) ?: realpath($part);
}
if ($full && is_dir($full)) {
$dirs[] = $full;
} else {
// try as-is
if (is_dir($part)) {
$dirs[] = realpath($part);
}
}
}
}
if (!empty($dirs)) {
$directoriesToScan = $dirs;
}
}
if ($directoriesToScan === null) {
$cwd = getcwd();
echo "No directory specified. Current directory is: {$cwd}\n";
if (!$skipVendor) {
echo "Skip vendor directories? (Y/n): ";
$r = trim(fgets(STDIN));
if ($r === '' || strtolower($r) !== 'n') {
$skipVendor = true;
}
}
echo "Scan all PHP files in this directory and subdirectories? (Y/n): ";
$r = trim(fgets(STDIN));
if (strtolower($r) === 'n') {
echo "\nEnter directories to scan (comma-separated paths, relative or absolute):\n";
echo "Example: src, ../other-project, /absolute/path/to/dir\n";
echo "Enter paths: ";
$input = trim(fgets(STDIN));
if ($input === '') {
echo "No directories selected. Scan cancelled.\n";
exit(0);
}
$parts = array_map('trim', explode(',', $input));
$dirs = [];
foreach ($parts as $part) {
if ($part === '') continue;
if (strpos($part, DIRECTORY_SEPARATOR) === 0) {
$full = $part;
} else {
$full = realpath($cwd . DIRECTORY_SEPARATOR . $part) ?: realpath($part);
}
if ($full && is_dir($full)) {
$dirs[] = $full;
} else {
echo "Warning: Directory not found or invalid: $part\n";
}
}
if (empty($dirs)) {
echo "No valid directories found. Scan cancelled.\n";
exit(0);
}
$directoriesToScan = $dirs;
}
}
echo "\nStarting PHP lint scan...\n";
echo "------------------------\n\n";
if (isset($directoriesToScan) && is_array($directoriesToScan)) {
$result = $runner->scanMultiple($directoriesToScan, $skipVendor, $verbose);
} else {
$result = $runner->scanDirectory(getcwd(), $skipVendor, $verbose);
}
echo "\n------------------------\n";
echo "Files checked: " . ($result['filesChecked'] ?? 0) . "\n";
if (!empty($result['filesSkipped'])) {
echo "Files skipped (in vendor directories): " . $result['filesSkipped'] . "\n";
}
if ($result['success']) {
echo "All files passed!\n";
} else {
echo "Errors were found:\n\n";
foreach ($result['errors'] as $error) {
echo "File: {$error['file']}\n";
echo "Error: {$error['message']}\n";
echo "------------------------\n";
}
}
if (!empty($result['permissionDenied'])) {
echo "\nPermission Denied (skipped):\n";
foreach ($result['permissionDenied'] as $deniedPath) {
echo "- $deniedPath\n";
}
}
exit($result['success'] ? 0 : 1);