Skip to content

Commit

Permalink
Fix #1141 - add symlinked symlinked repos to directory list
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 6, 2019
1 parent e3f2cee commit 07b29e4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions psalm.xml.dist
Expand Up @@ -22,8 +22,8 @@
<directory name="tests/DummyProject"/>
<file name="vendor/phpunit/phpunit/src/Framework/TestCase.php"/>
<file name="src/Psalm/Internal/Traverser/CustomTraverser.php"/>
<directory name="tests/performance/a.test"/>
<directory name="tests/performance/b.test"/>
<file name="tests/performance/a.test"/>
<file name="tests/performance/b.test"/>
<file name="tests/ErrorBaselineTest.php"/>
</ignoreFiles>
</projectFiles>
Expand Down
30 changes: 30 additions & 0 deletions src/Psalm/Config/FileFilter.php
Expand Up @@ -138,6 +138,36 @@ public static function loadFromXMLElement(
exit(1);
}

if (!is_dir($directory_path)) {
echo $base_dir . DIRECTORY_SEPARATOR . (string)$directory['name']
. ' is not a directory ' . PHP_EOL;
exit(1);
}

/** @var \RecursiveDirectoryIterator */
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory_path));
$iterator->rewind();

while ($iterator->valid()) {
if (!$iterator->isDot() && $iterator->isLink()) {
$linked_path = readlink($iterator->getPathName());

if (stripos($linked_path, $directory_path) !== 0) {
if ($ignore_type_stats && $filter instanceof ProjectFileFilter) {
$filter->ignore_type_stats[$directory_path] = true;
}

if ($declare_strict_types && $filter instanceof ProjectFileFilter) {
$filter->declare_strict_types[$directory_path] = true;
}

$filter->addDirectory(readlink($iterator->getPathName()));
}
}

$iterator->next();
}

if ($ignore_type_stats && $filter instanceof ProjectFileFilter) {
$filter->ignore_type_stats[$directory_path] = true;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/ConfigTest.php
Expand Up @@ -139,6 +139,38 @@ public function testIgnoreProjectDirectory()
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringAnalyzer.php')));
}

/**
* @return void
*/
public function testIgnoreSymlinkedProjectDirectory()
{
@unlink(__DIR__ . '/symlinktest/ignored/b');
symlink(__DIR__ . '/symlinktest/a', __DIR__ . '/symlinktest/ignored/b');

$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
Config::loadFromXML(
dirname(__DIR__),
'<?xml version="1.0"?>
<psalm>
<projectFiles>
<directory name="tests" />
<ignoreFiles>
<directory name="tests/symlinktest/ignored" />
</ignoreFiles>
</projectFiles>
</psalm>'
)
);

$config = $this->project_analyzer->getConfig();

$this->assertTrue($config->isInProjectDirs(realpath('tests/AnnotationTest.php')));
$this->assertFalse($config->isInProjectDirs(realpath('tests/symlinktest/a/ignoreme.php')));
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringAnalyzer.php')));

unlink(__DIR__ . '/symlinktest/ignored/b');
}

/**
* @return void
*/
Expand Down
Empty file.

0 comments on commit 07b29e4

Please sign in to comment.