Skip to content

Commit

Permalink
removed first character from dependencies string if is a backslash (#342
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AlessandroMinoccheri authored Jan 20, 2023
1 parent 3c0eecc commit a9e6e0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Analyzer/FileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function enterNode(Node $node): void
$returnType = $node->returnType;
if ($returnType instanceof Node\Name\FullyQualified) {
$this->classDescriptionBuilder
->addDependency(new ClassDependency($returnType->toCodeString(), $returnType->getLine()));
->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine()));
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/Unit/Analyzer/FileVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,41 @@ public function getBookList(): QueryBuilder;

$this->assertCount(1, $violations);
}

public function test_it_handles_return_types(): void
{
$code = <<< 'EOF'
<?php
namespace Foo\Bar;
use Doctrine\MongoDB\Collection;
use Foo\Baz\Baz;
use Symfony\Component\HttpFoundation\Request;
class MyClass implements Baz
{
public function __construct(Request $request)
{
$collection = new Collection($request);
}
public function getRequest(): Request //the violations is reported here
{
return new Request();
}
}
EOF;

/** @var FileParser $fp */
$fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

$violations = new Violations();

$dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Foo', 'Symfony', 'Doctrine');
$dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software');

$this->assertCount(0, $violations);
}
}
3 changes: 2 additions & 1 deletion tests/Unit/Analyzer/FullyQualifiedClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public function test_should_have_root_ns_preserved(): void

public function test_should_have_ns_normalized(): void
{
$fqcn = FullyQualifiedClassName::fromString('\Food\Vegetables\Fruits\Banana');
$fqcn = FullyQualifiedClassName::fromString('Food\Vegetables\Fruits\Banana');

$this->assertEquals('Banana', $fqcn->className());
$this->assertEquals('Food\Vegetables\Fruits', $fqcn->namespace());
$this->assertEquals('Food\Vegetables\Fruits\Banana', $fqcn->toString());
}
}

0 comments on commit a9e6e0d

Please sign in to comment.