Skip to content

Commit

Permalink
Add option to ignore sub dependencies checking
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinloiseau committed Apr 18, 2020
1 parent 439d8fd commit 70fb43f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ You can configure the plugin via the [`COMPOSER_HOME/config.json`](https://getco
{
"config": {
"sllh-composer-versions-check": {
"ignore-sub-dependencies": false,
"show-links": false
}
}
}
```

* `ignore-sub-dependencies`: Shows only outdated package required in composer.json.
* `show-links`: Shows outdated package links. Set to `true` to get a larger output, like the demo.
10 changes: 9 additions & 1 deletion src/VersionsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,24 @@ final class VersionsCheck
* @param ArrayRepository $distRepository
* @param WritableRepositoryInterface $localRepository
* @param RootPackageInterface $rootPackage
* @param bool $ignoreSubDependencies
*/
public function checkPackages(ArrayRepository $distRepository, WritableRepositoryInterface $localRepository, RootPackageInterface $rootPackage)
public function checkPackages(ArrayRepository $distRepository, WritableRepositoryInterface $localRepository, RootPackageInterface $rootPackage, bool $ignoreSubDependencies)
{
$packages = $localRepository->getPackages();
$rootRequires = array_keys($rootPackage->getRequires()) + array_keys($rootPackage->getDevRequires());

foreach ($packages as $package) {
// Do not compare aliases. Aliased packages are also provided.
if ($package instanceof AliasPackage) {
continue;
}

// Sub dependencies are ignored and package is not require in root. Skip.
if ($ignoreSubDependencies && !in_array($package->getName(), $rootRequires, true)) {
continue;
}

// Old composer versions BC
$versionConstraint = class_exists('Composer\Semver\Constraint\Constraint')
? new Constraint('>', $package->getVersion())
Expand Down
5 changes: 4 additions & 1 deletion src/VersionsCheckPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ private function resolveOptions()
;

$options = array(
'ignore-sub-dependencies' => false,
'show-links' => false,
);

if (null === $pluginConfig) {
return $options;
}

$options['ignore-sub-dependencies'] = isset($pluginConfig['ignore-sub-dependencies']) ? (bool) $pluginConfig['ignore-sub-dependencies'] : $options['ignore-sub-dependencies'];
$options['show-links'] = isset($pluginConfig['show-links']) ? (bool) $pluginConfig['show-links'] : $options['show-links'];

return $options;
Expand All @@ -125,7 +127,8 @@ private function checkVersions(RepositoryManager $repositoryManager, RootPackage
$this->versionsCheck->checkPackages(
$repository,
$repositoryManager->getLocalRepository(),
$rootPackage
$rootPackage,
$this->options['ignore-sub-dependencies']
);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/VersionsCheckPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ public function getTestOptionsData()
'No option' => array(
null,
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
'Empty array options' => array(
array(),
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
Expand All @@ -105,6 +107,7 @@ public function getTestOptionsData()
),
),
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
Expand All @@ -115,6 +118,7 @@ public function getTestOptionsData()
),
),
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
Expand All @@ -125,6 +129,33 @@ public function getTestOptionsData()
),
),
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
'Activate ignore-sub-dependencies' => array(
array(
'config' => array(
'sllh-composer-versions-check' => array(
'ignore-sub-dependencies' => true,
),
),
),
array(
'ignore-sub-dependencies' => true,
'show-links' => false,
),
),
'Disable ignore-sub-dependencies' => array(
array(
'config' => array(
'sllh-composer-versions-check' => array(
'ignore-sub-dependencies' => false,
),
),
),
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
Expand All @@ -137,6 +168,7 @@ public function getTestOptionsData()
),
),
array(
'ignore-sub-dependencies' => false,
'show-links' => true,
),
),
Expand All @@ -149,6 +181,7 @@ public function getTestOptionsData()
),
),
array(
'ignore-sub-dependencies' => false,
'show-links' => false,
),
),
Expand Down
2 changes: 1 addition & 1 deletion tests/VersionsCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ public function testOutdatedWithLinks()
*/
private function checkPackages()
{
$this->versionsCheck->checkPackages($this->distRepository, $this->localRepository, $this->rootPackage);
$this->versionsCheck->checkPackages($this->distRepository, $this->localRepository, $this->rootPackage, false);
}
}

0 comments on commit 70fb43f

Please sign in to comment.