Skip to content

Fix FileVisitor issues with wrong class detection #508

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/Analyzer/FileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@
return;
}

if (FullyQualifiedClassName::isNotAValidFqcn($type->toString())) {
return;

Check warning on line 251 in src/Analyzer/FileVisitor.php

View check run for this annotation

Codecov / codecov/patch

src/Analyzer/FileVisitor.php#L251

Added line #L251 was not covered by tests
}

$this->classDescriptionBuilder
->addDependency(new ClassDependency($type->toString(), $node->getLine()));
}
Expand Down Expand Up @@ -314,6 +318,10 @@
return;
}

if (FullyQualifiedClassName::isNotAValidFqcn($returnType->toString())) {
return;

Check warning on line 322 in src/Analyzer/FileVisitor.php

View check run for this annotation

Codecov / codecov/patch

src/Analyzer/FileVisitor.php#L322

Added line #L322 was not covered by tests
}

$this->classDescriptionBuilder
->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine()));
}
Expand All @@ -330,6 +338,10 @@
return;
}

if (FullyQualifiedClassName::isNotAValidFqcn($nodeName->toString())) {
return;

Check warning on line 342 in src/Analyzer/FileVisitor.php

View check run for this annotation

Codecov / codecov/patch

src/Analyzer/FileVisitor.php#L342

Added line #L342 was not covered by tests
}

$this->classDescriptionBuilder
->addAttribute($node->name->toString(), $node->getLine());
}
Expand All @@ -346,6 +358,10 @@
return;
}

if (FullyQualifiedClassName::isNotAValidFqcn($type->toString())) {
return;

Check warning on line 362 in src/Analyzer/FileVisitor.php

View check run for this annotation

Codecov / codecov/patch

src/Analyzer/FileVisitor.php#L362

Added line #L362 was not covered by tests
}

$this->classDescriptionBuilder
->addDependency(new ClassDependency($type->toString(), $node->getLine()));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Analyzer/FullyQualifiedClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function toString(): string

public function classMatches(string $pattern): bool
{
if ($this->isNotAValidPattern($pattern)) {
if (self::isNotAValidFqcn($pattern)) {
throw new InvalidPatternException("'$pattern' is not a valid class or namespace pattern. Regex are not allowed, only * and ? wildcard.");
}

Expand All @@ -36,7 +36,7 @@ public function classMatches(string $pattern): bool

public function matches(string $pattern): bool
{
if ($this->isNotAValidPattern($pattern)) {
if (self::isNotAValidFqcn($pattern)) {
throw new InvalidPatternException("'$pattern' is not a valid class or namespace pattern. Regex are not allowed, only * and ? wildcard.");
}

Expand Down Expand Up @@ -69,12 +69,12 @@ public static function fromString(string $fqcn): self
return new self(new PatternString($fqcn), new PatternString($namespace), new PatternString($className));
}

public function isNotAValidPattern(string $pattern): bool
public static function isNotAValidFqcn(string $fqcn): bool
{
$validClassNameCharacters = '[a-zA-Z0-9_\x80-\xff]';
$or = '|';
$backslash = '\\\\';

return 0 === preg_match('/^('.$validClassNameCharacters.$or.$backslash.$or.'\*'.$or.'\?)*$/', $pattern);
return 0 === preg_match('/^('.$validClassNameCharacters.$or.$backslash.$or.'\*'.$or.'\?)*$/', $fqcn);
}
}