From 5fdba72430cf2e4d579090abe4edfd33268ce76f Mon Sep 17 00:00:00 2001 From: ZinitSolutionsGmbH Date: Tue, 28 Feb 2017 22:11:14 +0700 Subject: [PATCH] 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. --- src/PHPCensor/Plugin/PhpCpd.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/PHPCensor/Plugin/PhpCpd.php b/src/PHPCensor/Plugin/PhpCpd.php index cc17c7c8..5b19df35 100644 --- a/src/PHPCensor/Plugin/PhpCpd.php +++ b/src/PHPCensor/Plugin/PhpCpd.php @@ -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');