Skip to content

Commit

Permalink
Fix template discovery, to include root file too (TomasVotruba#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored and ngmy committed Dec 19, 2024
1 parent b74eae4 commit 502706d
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 @@ -59,7 +59,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 502706d

Please sign in to comment.