Problem with plugin: sends the wrong command to ignore the files. When we ignore

the directory, we use --exclude path/dir_1 --exclude path/dir_2 --exclude path/dir_3
everything works correctly but when we want to exclude file - PhpCpd.php
sends command like --names-exclude path/file_1 --names-exclude path/file_2
--names-exlcude path/file_3 and files will be scanned for copy/past, to ignore all three file we have to use
command like --names-exclude file_1,file_2,file_3 without paths.
This commit is contained in:
ZinitSolutionsGmbH 2017-02-28 22:11:14 +07:00 committed by Dmitry Khomutov
parent d8fbbd739b
commit 5fdba72430
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9

View file

@ -85,26 +85,27 @@ class PhpCpd extends Plugin implements ZeroConfigPluginInterface
}
/**
* Runs PHP Copy/Paste Detector in a specified directory.
*/
* Runs PHP Copy/Paste Detector in a specified directory.
*/
public function execute()
{
$ignore = '';
if (count($this->ignore)) {
$map = function ($item) {
// remove the trailing slash
$item = rtrim($item, DIRECTORY_SEPARATOR);
$namesExclude = ' --names-exclude ';
foreach ($this->ignore as $item) {
// remove the trailing slash
$item = rtrim($item, DIRECTORY_SEPARATOR);
if (is_file(rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $item)) {
return ' --names-exclude ' . $item;
} else {
return ' --exclude ' . $item;
}
if (is_file(rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $item)) {
$ignoredFile = explode('/', $item);
$filesToIgnore[] = array_pop($ignoredFile);
} else {
$ignore .= ' --exclude ' . $item;
}
}
};
$ignore = array_map($map, $this->ignore);
$ignore = implode('', $ignore);
if (isset($filesToIgnore)) {
$filesToIgnore = $namesExclude . implode(',', $filesToIgnore);
$ignore = $ignore . $filesToIgnore;
}
$phpcpd = $this->builder->findBinary('phpcpd');