Skip to content
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

Fix template discovery, to include root file too #127

Merged
merged 1 commit into from
Sep 16, 2024
Merged
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
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);
}
}
Loading