-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the excludePackage option
- Loading branch information
1 parent
ec01562
commit 5e8705d
Showing
9 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Icanhazstring\Composer\Unused\Command; | ||
|
||
use Icanhazstring\Composer\Unused\Dependency\DependencyCollection; | ||
|
||
use function array_merge; | ||
|
||
final class FilterDependencyCollectionCommand | ||
{ | ||
private const GLOBAL_EXCLUSION = [ | ||
'composer-plugin-api', | ||
]; | ||
|
||
/** @var DependencyCollection */ | ||
private $requiredDependencyCollection; | ||
/** @var array<string> */ | ||
private $namedExclusion; | ||
|
||
/** | ||
* @param DependencyCollection $requiredDependencyCollection | ||
* @param array<string> $namedExclusion | ||
*/ | ||
public function __construct(DependencyCollection $requiredDependencyCollection, array $namedExclusion) | ||
{ | ||
$this->requiredDependencyCollection = $requiredDependencyCollection; | ||
$this->namedExclusion = array_merge(self::GLOBAL_EXCLUSION, $namedExclusion); | ||
} | ||
|
||
public function getRequiredDependencyCollection(): DependencyCollection | ||
{ | ||
return $this->requiredDependencyCollection; | ||
} | ||
|
||
/** | ||
* @return array<string> | ||
*/ | ||
public function getNamedExclusion(): array | ||
{ | ||
return $this->namedExclusion; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Command/Handler/CollectFilteredDependenciesCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Icanhazstring\Composer\Unused\Command\Handler; | ||
|
||
use Icanhazstring\Composer\Unused\Command\FilterDependencyCollectionCommand; | ||
use Icanhazstring\Composer\Unused\Dependency\DependencyCollection; | ||
|
||
final class CollectFilteredDependenciesCommandHandler | ||
{ | ||
public function collect(FilterDependencyCollectionCommand $command): DependencyCollection | ||
{ | ||
$dependencyCollection = new DependencyCollection(); | ||
$namedExclusion = $command->getNamedExclusion(); | ||
|
||
foreach ($command->getRequiredDependencyCollection() as $dependency) { | ||
if (!in_array($dependency->getName(), $namedExclusion)) { | ||
$dependencyCollection->add($dependency); | ||
} | ||
} | ||
|
||
return $dependencyCollection; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Command/Handler/Factory/CollectFilteredDependenciesCommandHandlerFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Icanhazstring\Composer\Unused\Command\Handler\Factory; | ||
|
||
use Icanhazstring\Composer\Unused\Command\Handler\CollectFilteredDependenciesCommandHandler; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class CollectFilteredDependenciesCommandHandlerFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): CollectFilteredDependenciesCommandHandler | ||
{ | ||
return new CollectFilteredDependenciesCommandHandler(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/assets/TestProjects/IgnoreExcludedPackages/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "ns/lib", | ||
"require": { | ||
"dummy/test-package": "1.0", | ||
"composer-plugin-api": "^2.0" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/assets/TestProjects/IgnoreSpecialPackages/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "ns/lib", | ||
"require": { | ||
"composer-plugin-api": "^2.0" | ||
} | ||
} |