function Plugin::updateInstalledPaths
Check all installed packages (including the root package) against the installed paths from PHP_CodeSniffer and add the missing ones.
Return value
bool True if changes where made, false otherwise
Throws
\InvalidArgumentException
\RuntimeException
1 call to Plugin::updateInstalledPaths()
- Plugin::onDependenciesChangedEvent in vendor/
dealerdirect/ phpcodesniffer-composer-installer/ src/ Plugin.php - Entry point for post install and post update events.
File
-
vendor/
dealerdirect/ phpcodesniffer-composer-installer/ src/ Plugin.php, line 445
Class
- Plugin
- PHP_CodeSniffer standard installation manager.
Namespace
PHPCSStandards\Composer\Plugin\Installers\PHPCodeSnifferCode
private function updateInstalledPaths() {
$changes = false;
$searchPaths = array();
// Add root package only if it has the expected package type.
if ($this->composer
->getPackage() instanceof RootPackageInterface && $this->composer
->getPackage()
->getType() === self::PACKAGE_TYPE) {
$searchPaths[] = $this->cwd;
}
$codingStandardPackages = $this->getPHPCodingStandardPackages();
foreach ($codingStandardPackages as $package) {
$installPath = $this->composer
->getInstallationManager()
->getInstallPath($package);
if ($this->filesystem
->isAbsolutePath($installPath) === false) {
$installPath = $this->filesystem
->normalizePath($this->cwd . \DIRECTORY_SEPARATOR . $installPath);
}
$searchPaths[] = $installPath;
}
// Nothing to do.
if ($searchPaths === array()) {
return false;
}
$finder = new Finder();
$finder->files()
->depth('<= ' . $this->getMaxDepth())
->depth('>= ' . $this->getMinDepth())
->ignoreUnreadableDirs()
->ignoreVCS(true)
->in($searchPaths)
->name('ruleset.xml');
// Process each found possible ruleset.
foreach ($finder as $ruleset) {
$standardsPath = $ruleset->getPath();
// Pick the directory above the directory containing the standard, unless this is the project root.
if ($standardsPath !== $this->cwd) {
$standardsPath = dirname($standardsPath);
}
// Use relative paths for local project repositories.
if ($this->isRunningGlobally() === false) {
$standardsPath = $this->filesystem
->findShortestPath($this->getPHPCodeSnifferInstallPath(), $standardsPath, true);
}
// De-duplicate and add when directory is not configured.
if (in_array($standardsPath, $this->installedPaths, true) === false) {
$this->installedPaths[] = $standardsPath;
$changes = true;
}
}
return $changes;
}