Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for having coding standards in the root package #25

Merged
merged 1 commit into from May 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/Plugin.php
Expand Up @@ -251,8 +251,8 @@ private function cleanInstalledPaths()
}

/**
* Check all installed packages against the installed paths from
* PHP_CodeSniffer and add the missing ones.
* Check all installed packages (including the root package) against
* the installed paths from PHP_CodeSniffer and add the missing ones.
*
* @return bool True if changes where made, false otherwise
*
Expand All @@ -261,23 +261,26 @@ private function cleanInstalledPaths()
private function updateInstalledPaths()
{
$changes = false;
$codingStandardPackages = $this->getPHPCodingStandardPackages();

$searchPaths = [getcwd()];
Copy link
Member

@Potherca Potherca May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness sake: although usually using getcwd (and consorts) is discouraged, this is the "Composer Way" of doing things.

$codingStandardPackages = $this->getPHPCodingStandardPackages();
foreach ($codingStandardPackages as $package) {
$packageInstallPath = $this->composer->getInstallationManager()->getInstallPath($package);
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->in($packageInstallPath)
->depth('>= 1')
->depth('< 4')
->name('ruleset.xml');
foreach ($finder as $ruleset) {
$standardsPath = dirname(dirname($ruleset));
if (in_array($standardsPath, $this->installedPaths, true) === false) {
$this->installedPaths[] = $standardsPath;
$changes = true;
}
$searchPaths[] = $this->composer->getInstallationManager()->getInstallPath($package);
}

$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->depth('>= 1')
->depth('< 4')
->name('ruleset.xml')
->in($searchPaths);

foreach ($finder as $ruleset) {
$standardsPath = dirname(dirname($ruleset));
if (in_array($standardsPath, $this->installedPaths, true) === false) {
$this->installedPaths[] = $standardsPath;
$changes = true;
}
}

Expand All @@ -287,8 +290,8 @@ private function updateInstalledPaths()
/**
* Iterates through Composers' local repository looking for valid Coding
* Standard packages.
*
* If the package is the RootPackage (the one the plugin is installed into),
*
* If the package is the RootPackage (the one the plugin is installed into),
* the package is ignored for now since it needs a different install path logic.
*
* @return array Composer packages containing coding standard(s)
Expand Down