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 c824838
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"phpstan/extension-installer": "^1.4",
"tracy/tracy": "^2.10",
"symplify/easy-coding-standard": "^12.3",
"rector/rector": "^1.2.4",
"rector/rector": "^1.2.5",
"phpunit/phpunit": "^10.5",
"tomasvotruba/class-leak": "^0.2.11",
"tomasvotruba/type-coverage": "^0.3",
"symplify/easy-ci": "^12.0",
"shipmonk/composer-dependency-analyser": "^1.5",
"symplify/easy-ci": "^12.1",
"shipmonk/composer-dependency-analyser": "^1.7",
"symplify/phpstan-rules": "^13.0"
},
"autoload": {
Expand Down
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 c824838

Please sign in to comment.