Skip to content

Commit

Permalink
Fix ignoring phpmd/pdepend directories on Windows - closes #75
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenekdrahos committed Jul 1, 2017
1 parent 5858f8d commit f1c9983
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/IgnoredPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ class IgnoredPaths
private $ignoreDirs;
private $ignoreFiles;
private $ignoreBoth;
private $isWindows;

public function __construct($ignoredDirs, $ignoredFiles)
{
$this->ignoreDirs = $this->csvToArray($ignoredDirs);
$this->ignoreFiles = $this->csvToArray($ignoredFiles);
$this->ignoreBoth = array_merge($this->ignoreDirs, $this->ignoreFiles);
$this->setOS(PHP_OS);
}

public function setOS($os)
{
$this->isWindows = strtoupper(substr($os, 0, 3)) == 'WIN';
}

private function csvToArray($csv)
Expand All @@ -27,14 +34,25 @@ public function phpcs()

public function pdepend()
{
if ($this->isWindows) {
return $this->pdependFilter('ignore');
}
return $this->ignore(' --ignore=/', '/,/', '/', ',/');
}

public function phpmd()
{
if ($this->isWindows) {
return $this->pdependFilter('exclude');
}
return $this->ignore(" --exclude /", '/,/', '/', ',/');
}

private function pdependFilter($option)
{
return $this->ignore(" --{$option}=", '\*,', '\*', ',');
}

public function phpmetrics()
{
return $this->ignore(' --excluded-dirs="', '|', '"');
Expand Down
35 changes: 31 additions & 4 deletions tests/IgnoredPathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

class IgnoredPathsTest extends \PHPUnit_Framework_TestCase
{
private $operatingSystem = 'Linux';

private function ignore($tool, $dirs, $files)
{
$paths = new IgnoredPaths($dirs, $files);
$paths->setOS($this->operatingSystem);
return $paths->$tool();
}

Expand All @@ -17,11 +20,17 @@ public function testNoOptionWhenNothingIsIgnored($tool)
}

/** @dataProvider provideTools */
public function testShouldIgnoreDirectories($tool, $expectedOptions)
public function testIgnoreDirectoriesAndFiles($tool, $expectedOptions, $os = null)
{
assertThat($this->ignore($tool, 'bin,vendor', 'autoload.php,RoboFile.php'), is($expectedOptions['both']));
assertThat($this->ignore($tool, 'bin,vendor', ''), is($expectedOptions['dirs']));
assertThat($this->ignore($tool, '', 'autoload.php,RoboFile.php'), is($expectedOptions['files']));
$this->operatingSystem = $os ?: $this->operatingSystem;
$this->assertEquals(
$expectedOptions,
[
'both' => $this->ignore($tool, 'bin,vendor', 'autoload.php,RoboFile.php'),
'dirs' => $this->ignore($tool, 'bin,vendor', ''),
'files' => $this->ignore($tool, '', 'autoload.php,RoboFile.php'),
]
);
}

public function provideTools()
Expand Down Expand Up @@ -51,6 +60,24 @@ public function provideTools()
'files' => ' --exclude /autoload.php,/RoboFile.php'
)
),
'pdepend + windows' => array(
'pdepend',
array(
'both' => ' --ignore=bin\*,vendor\*,autoload.php,RoboFile.php',
'dirs' => ' --ignore=bin\*,vendor\*',
'files' => ' --ignore=autoload.php,RoboFile.php'
),
'Windows'
),
'phpmd + windows' => array(
'phpmd',
array(
'both' => ' --exclude=bin\*,vendor\*,autoload.php,RoboFile.php',
'dirs' => ' --exclude=bin\*,vendor\*',
'files' => ' --exclude=autoload.php,RoboFile.php'
),
'WIN32'
),
array(
'phpmetrics',
array(
Expand Down

0 comments on commit f1c9983

Please sign in to comment.