Skip to content

Commit

Permalink
fix template discovery, to include root file too
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 16, 2024
1 parent 4d712cb commit 494a2e9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Collectors/PublicStaticPropertyFetchCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function processNode(Node $node, Scope $scope): ?array
return null;
}

$classType = $node->class instanceof Name ? $scope->resolveTypeByName($node->class) : $scope->getType($node->class);
$classType = $node->class instanceof Name ? $scope->resolveTypeByName($node->class) : $scope->getType(
$node->class
);

$result = [];
foreach ($classType->getObjectClassReflections() as $classReflection) {
Expand Down
5 changes: 5 additions & 0 deletions src/Finder/TemplateFilesFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace TomasVotruba\UnusedPublic\Finder;

/**
* @see \TomasVotruba\UnusedPublic\Tests\Templates\TemplateFilesFinder\TemplateFilesFinderTest
*/
final class TemplateFilesFinder
{
/**
Expand All @@ -15,10 +18,12 @@ public static function findTemplateFilePaths(array $directories, string $suffix)
$templateFilePaths = [];

foreach ($directories as $directory) {
$currentTemplateFilePathsL0 = glob($directory . '/*.' . $suffix);
$currentTemplateFilePathsL1 = glob($directory . '/*/*.' . $suffix);
$currentTemplateFilePathsL2 = glob($directory . '/**/*/*.' . $suffix);

$currentTemplateFilePaths = array_merge(
$currentTemplateFilePathsL0 === false ? [] : $currentTemplateFilePathsL0,
$currentTemplateFilePathsL1 === false ? [] : $currentTemplateFilePathsL1,
$currentTemplateFilePathsL2 === false ? [] : $currentTemplateFilePathsL2
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
first
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
second
15 changes: 15 additions & 0 deletions tests/Templates/TemplateFilesFinder/TemplateFilesFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace TomasVotruba\UnusedPublic\Tests\Templates\TemplateFilesFinder;

use PHPUnit\Framework\TestCase;
use TomasVotruba\UnusedPublic\Finder\TemplateFilesFinder;

final class TemplateFilesFinderTest extends TestCase
{
public function test(): void
{
$twigFilePaths = TemplateFilesFinder::findTemplateFilePaths([__DIR__ . '/Fixture'], 'twig');
$this->assertCount(2, $twigFilePaths);
}
}

0 comments on commit 494a2e9

Please sign in to comment.