Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 18, 2023
1 parent 6cf8422 commit ca420cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
6 changes: 1 addition & 5 deletions app/ClassNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TomasVotruba\ClassLeak;

use Nette\Utils\FileSystem;
use PhpParser\NodeTraverser;
use PhpParser\Parser;
use TomasVotruba\ClassLeak\NodeDecorator\FullyQualifiedNameNodeDecorator;
Expand All @@ -21,12 +20,9 @@ public function __construct(
) {
}

/**
* @api
*/
public function resolveFromFromFilePath(string $filePath): ?string
{
$fileContents = FileSystem::read($filePath);
$fileContents = file_get_contents($filePath);

$stmts = $this->parser->parse($fileContents);
if ($stmts === null) {
Expand Down
38 changes: 18 additions & 20 deletions app/UseImportsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TomasVotruba\ClassLeak;

use Nette\Utils\FileSystem;
use PhpParser\NodeTraverser;
use PhpParser\Parser;
use TomasVotruba\ClassLeak\NodeDecorator\FullyQualifiedNameNodeDecorator;
Expand All @@ -21,31 +20,30 @@ public function __construct(
) {
}

/**
* @param string[] $filePaths
* @return string[]
*@api
*/
public function resolveFromFilePaths(array $filePaths): array
{
$usedNames = [];

foreach ($filePaths as $filePath) {
$usedNames = array_merge($usedNames, $this->resolve($filePath));
}

$usedNames = array_unique($usedNames);
sort($usedNames);

return $usedNames;
}
// /**
// * @param string[] $filePath
// * @return string[]
// */
// public function resolveFromFilePaths(array $filePaths): array
// {
// $usedNames = [];
//
// foreach ($filePaths as $filePath) {
// $usedNames = array_merge($usedNames, $this->resolve($filePath));
// }
//
// $usedNames = array_unique($usedNames);
// sort($usedNames);
//
// return $usedNames;
// }

/**
* @return string[]
*/
public function resolve(string $filePath): array
{
$fileContents = FileSystem::read($filePath);
$fileContents = file_get_contents($filePath);

$stmts = $this->parser->parse($fileContents);
if ($stmts === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ protected function setUp(): void
}

/**
* @param string[] $filePaths
* @param string[] $expectedClassUsages
*/
#[DataProvider('provideData')]
public function test(array $filePaths, array $expectedClassUsages): void
public function test(string $filePath, array $expectedClassUsages): void
{
$resolvedClassUsages = $this->useImportsResolver->resolveFromFilePaths($filePaths);
$resolvedClassUsages = $this->useImportsResolver->resolve($filePath);
$this->assertSame($expectedClassUsages, $resolvedClassUsages);
}

public static function provideData(): Iterator
{
yield [[__DIR__ . '/Fixture/FileUsingOtherClasses.php'], [FirstUsedClass::class, SecondUsedClass::class]];
yield [__DIR__ . '/Fixture/FileUsingOtherClasses.php', [FirstUsedClass::class, SecondUsedClass::class]];
}
}

0 comments on commit ca420cf

Please sign in to comment.