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

Adding excluding dependencies as parameters #220

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 deletions src/Expression/ForClasses/Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

class Extend implements Expression
{
/**
* @var string
*/
/** @var string */
private $className;

public function __construct(string $className)
Expand Down
4 changes: 1 addition & 3 deletions src/Expression/ForClasses/NotExtend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

class NotExtend implements Expression
{
/**
* @var string
*/
/** @var string */
private $className;

public function __construct(string $className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class NotHaveDependencyOutsideNamespace implements Expression
{
/** @var string */
private $namespace;
/** @var array */
private $externalDependenciesToExclude;

public function __construct(string $namespace)
public function __construct(string $namespace, array $externalDependenciesToExclude = [])
{
$this->namespace = $namespace;
$this->externalDependenciesToExclude = $externalDependenciesToExclude;
}

public function describe(ClassDescription $theClass): Description
Expand All @@ -38,6 +41,10 @@ public function evaluate(ClassDescription $theClass, Violations $violations): vo

/** @var ClassDependency $externalDep */
foreach ($externalDeps as $externalDep) {
if ($externalDep->matchesOneOf(...$this->externalDependenciesToExclude)) {
continue;
}

$violation = Violation::createWithErrorLine(
$theClass->getFQCN(),
$this->describe($theClass)->toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ public function test_it_should_return_false_if_depends_on_namespace(): void
$notHaveDependencyOutsideNamespace->evaluate($classDescription, $violations);
self::assertNotEquals(0, $violations->count());
}

public function test_it_should_not_return_violation_error_if_dependency_excluded(): void
{
$notHaveDependencyOutsideNamespace = new NotHaveDependencyOutsideNamespace('myNamespace', ['foo']);
$classDescription = new ClassDescription(
FullyQualifiedClassName::fromString('HappyIsland'),
[new ClassDependency('foo', 100)],
[],
null
);

$violations = new Violations();
$notHaveDependencyOutsideNamespace->evaluate($classDescription, $violations);
self::assertEquals(0, $violations->count());
}
}