@@ -56,8 +56,7 @@ public function setBlackList(array $blackList)
56
56
*/
57
57
public function canRun ()
58
58
{
59
- $ vendorDir = require BP . '/app/etc/vendor_path.php ' ;
60
- exec ('php ' . BP . '/ ' . $ vendorDir . '/bin/phpcpd --version ' , $ output , $ exitCode );
59
+ exec ($ this ->getCommand () . ' --version ' , $ output , $ exitCode );
61
60
return $ exitCode === 0 ;
62
61
}
63
62
@@ -71,22 +70,37 @@ public function canRun()
71
70
*/
72
71
public function run (array $ whiteList )
73
72
{
74
- $ blackListStr = ' ' ;
73
+ $ blacklistedDirs = [];
74
+ $ blacklistedFileNames = [];
75
75
foreach ($ this ->blacklist as $ file ) {
76
76
$ file = escapeshellarg (trim ($ file ));
77
77
if (!$ file ) {
78
78
continue ;
79
79
}
80
- $ blackListStr .= '--exclude ' . $ file . ' ' ;
80
+ $ ext = pathinfo ($ file , PATHINFO_EXTENSION );
81
+ if ($ ext != '' ) {
82
+ $ blacklistedFileNames [] = $ file ;
83
+ } else {
84
+ $ blacklistedDirs [] = '--exclude ' . $ file . ' ' ;
85
+ }
81
86
}
82
87
83
- $ vendorDir = require BP . '/app/etc/vendor_path.php ' ;
84
- $ command = 'php ' . BP . '/ ' . $ vendorDir . '/bin/phpcpd ' . ' --log-pmd ' . escapeshellarg (
85
- $ this ->reportFile
86
- ) . ' --names-exclude "*Test.php" --min-lines 13 ' . $ blackListStr . ' ' . implode (' ' , $ whiteList );
87
-
88
+ $ command = $ this ->getCommand () . ' --log-pmd ' . escapeshellarg ($ this ->reportFile )
89
+ . ' --names-exclude ' . join (', ' , $ blacklistedFileNames ) . ' --min-lines 13 ' . join (' ' , $ blacklistedDirs )
90
+ . ' ' . implode (' ' , $ whiteList );
88
91
exec ($ command , $ output , $ exitCode );
89
92
90
93
return !(bool )$ exitCode ;
91
94
}
95
+
96
+ /**
97
+ * Get PHPCPD command
98
+ *
99
+ * @return string
100
+ */
101
+ private function getCommand ()
102
+ {
103
+ $ vendorDir = require BP . '/app/etc/vendor_path.php ' ;
104
+ return 'php ' . BP . '/ ' . $ vendorDir . '/bin/phpcpd ' ;
105
+ }
92
106
}
0 commit comments