-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from akeneo/list-unused-reqs
Add list-unused-requirements command
- Loading branch information
Showing
11 changed files
with
434 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# List unused requirements | ||
|
||
The _list-unused-requirements_ command is a complementary tool to the _detect_ command that allows you to easily clean | ||
your configuration. It lists the requirements that are not necessary anymore for each rule : | ||
|
||
```bash | ||
php bin/php-coupling-detector list-unused-requirements | ||
``` | ||
|
||
Like the _detect_ command, you can specify the path to the configuration file with the ``--config-file`` option. | ||
|
||
The exit status of the _list-unused-requirements_ command can be: ``10`` if some unused requirements have been found, | ||
or ``0`` otherwise. | ||
|
||
Please note that for the moment this is relevant only for rules of type ``ONLY`` as the notion of "unused requirement" | ||
in a ``DISCOURAGED`` or ``FORBIDDEN`` rule makes no sense. |
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,81 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\CouplingDetector\Domain; | ||
|
||
use Akeneo\CouplingDetector\Domain\Node; | ||
use Akeneo\CouplingDetector\Domain\NodeInterface; | ||
use Akeneo\CouplingDetector\Domain\Rule; | ||
use Akeneo\CouplingDetector\Domain\RuleInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class RuleSpec extends ObjectBehavior | ||
{ | ||
function let() | ||
{ | ||
$this->beConstructedWith( | ||
'Namespace\To\Check', | ||
[ | ||
'Authorized\Namespace\One', | ||
'Authorized\Namespace\Two', | ||
'Authorized\Namespace\Three', | ||
'Authorized\Namespace\Four', | ||
], | ||
RuleInterface::TYPE_ONLY | ||
); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldBeAnInstanceOf(Rule::class); | ||
} | ||
|
||
function it_matches_a_node(NodeInterface $node) | ||
{ | ||
$node->getSubject()->willReturn('Namespace\To\Check\SomeClass'); | ||
$this->matches($node)->shouldReturn(true); | ||
|
||
$node->getSubject()->willReturn('Another\Namespace\SomeClass'); | ||
$this->matches($node)->shouldReturn(false); | ||
} | ||
|
||
function it_finds_which_of_its_requirements_are_unused_in_a_set_of_nodes() | ||
{ | ||
// We only test this case for Rules of type "ONLY". It is not applicable for other types. | ||
// The fact that this method has a very different behavior depending on an immutable property (the type) and not | ||
// on the inputs probably shows that the class should be split (one class per type). | ||
$this->getUnusedRequirements( | ||
[ | ||
new Node( | ||
[ | ||
'Authorized\Namespace\One', | ||
'Authorized\Namespace\Three', | ||
], | ||
'Namespace\To\Check\ClassOne', | ||
'/path/to/file', | ||
RuleInterface::TYPE_ONLY | ||
), | ||
new Node( | ||
[ | ||
'Authorized\Namespace\One', | ||
], | ||
'Namespace\To\Check\ClassTwo', | ||
'/path/to/file', | ||
RuleInterface::TYPE_ONLY | ||
), | ||
new Node( | ||
[ | ||
'Authorized\Namespace\Two', | ||
], | ||
'Namespace\Not\To\Check\ClassThree', | ||
'/path/to/file', | ||
RuleInterface::TYPE_ONLY | ||
), | ||
] | ||
)->shouldReturn( | ||
[ | ||
1 => 'Authorized\Namespace\Two', | ||
3 => 'Authorized\Namespace\Four', | ||
] | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.