Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Create a composer package of your coding standard by adding a `composer.json` fi
```

Requirements:
* The repository may contain one or more standards. Each in their separate directory in the root of your repository.
* The repository may contain one or more standards.
* Each standard can have a separate directory no deeper than 3 levels from the repository root.
* The package `type` must be `phpcodesniffer-standard`. Without this, the plugin will not trigger.

[this]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial
Expand Down
30 changes: 22 additions & 8 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Composer\Package\PackageInterface;
use Composer\Plugin\PluginInterface;
use Composer\Script\ScriptEvents;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\RuntimeException;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static function getSubscribedEvents()
}

/**
* Entry point for post install and post update events
* Entry point for post install and post update events.
*
* @throws RuntimeException
* @throws LogicException
Expand All @@ -107,7 +108,7 @@ public function onDependenciesChangedEvent()
}

/**
* Load all paths from PHP_CodeSniffer into an array
* Load all paths from PHP_CodeSniffer into an array.
*
* @throws RuntimeException
* @throws LogicException
Expand Down Expand Up @@ -157,7 +158,8 @@ private function saveInstalledPaths()
/**
* Iterate trough all known paths and check if they are still valid.
*
* If path does not exists, is not an directory or isn't readble, the path is removed from the list.
* If path does not exists, is not an directory or isn't readable, the path
* is removed from the list.
*
* @return bool True if changes where made, false otherwise
*/
Expand All @@ -174,7 +176,8 @@ private function cleanInstalledPaths()
}

/**
* Check all installed packages against the installed paths from PHP_CodeSniffer and add the missing ones.
* Check all installed packages against the installed paths from
* PHP_CodeSniffer and add the missing ones.
*
* @return bool True if changes where made, false otherwise
*/
Expand All @@ -185,17 +188,28 @@ private function updateInstalledPaths()

foreach ($codingStandardPackages as $package) {
$packageInstallPath = $this->composer->getInstallationManager()->getInstallPath($package);
if (in_array($packageInstallPath, $this->installedPaths, true) === false) {
$this->installedPaths[] = $packageInstallPath;
$changes = true;
$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;
}
}
}

return $changes;
}

/**
* Iterates trough Composers' local repository looking for valid Coding Standard packages
* Iterates through Composers' local repository looking for valid Coding
* Standard packages.
*
* @return array Composer packages containing coding standard(s)
*/
Expand Down