Skip to content

Commit a9e6e0d

Browse files
removed first character from dependencies string if is a backslash (#342)
1 parent 3c0eecc commit a9e6e0d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/Analyzer/FileVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function enterNode(Node $node): void
187187
$returnType = $node->returnType;
188188
if ($returnType instanceof Node\Name\FullyQualified) {
189189
$this->classDescriptionBuilder
190-
->addDependency(new ClassDependency($returnType->toCodeString(), $returnType->getLine()));
190+
->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine()));
191191
}
192192
}
193193
}

tests/Unit/Analyzer/FileVisitorTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,4 +730,41 @@ public function getBookList(): QueryBuilder;
730730

731731
$this->assertCount(1, $violations);
732732
}
733+
734+
public function test_it_handles_return_types(): void
735+
{
736+
$code = <<< 'EOF'
737+
<?php
738+
namespace Foo\Bar;
739+
740+
use Doctrine\MongoDB\Collection;
741+
use Foo\Baz\Baz;
742+
use Symfony\Component\HttpFoundation\Request;
743+
744+
class MyClass implements Baz
745+
{
746+
public function __construct(Request $request)
747+
{
748+
$collection = new Collection($request);
749+
}
750+
751+
public function getRequest(): Request //the violations is reported here
752+
{
753+
return new Request();
754+
}
755+
}
756+
EOF;
757+
758+
/** @var FileParser $fp */
759+
$fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
760+
$fp->parse($code, 'relativePathName');
761+
$cd = $fp->getClassDescriptions();
762+
763+
$violations = new Violations();
764+
765+
$dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('Foo', 'Symfony', 'Doctrine');
766+
$dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software');
767+
768+
$this->assertCount(0, $violations);
769+
}
733770
}

tests/Unit/Analyzer/FullyQualifiedClassNameTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ public function test_should_have_root_ns_preserved(): void
5757

5858
public function test_should_have_ns_normalized(): void
5959
{
60-
$fqcn = FullyQualifiedClassName::fromString('\Food\Vegetables\Fruits\Banana');
60+
$fqcn = FullyQualifiedClassName::fromString('Food\Vegetables\Fruits\Banana');
6161

6262
$this->assertEquals('Banana', $fqcn->className());
6363
$this->assertEquals('Food\Vegetables\Fruits', $fqcn->namespace());
64+
$this->assertEquals('Food\Vegetables\Fruits\Banana', $fqcn->toString());
6465
}
6566
}

0 commit comments

Comments
 (0)