Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed Dec 28, 2023
1 parent dc62cb2 commit eea09ff
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
33 changes: 24 additions & 9 deletions src/Analyzers/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\ClassMapGenerator\ClassMapGenerator;
use ImanGhafoori\ComposerJson\ComposerJson as Composer;
use Imanghafoori\LaravelMicroscope\FileReaders\FilePath;

class ComposerJson
{
Expand All @@ -24,19 +25,33 @@ public static function autoloadedFilesList($basePath)
return self::make()->autoloadedFilesList($basePath);
}

public static function getClassMaps($basePath)
public static function getClassMaps($basePath, $folder = '', $fileName = '')
{
$result = [];
foreach (self::make()->readAutoloadClassMap() as $compPath => $classMaps) {
foreach ($classMaps as $classmap) {
$compPath1 = trim($compPath, '/');
$compPath1 = $compPath1 ? $compPath1.DIRECTORY_SEPARATOR : '';
$classmapFullPath = $basePath.DIRECTORY_SEPARATOR.$compPath1.$classmap;
$classes = array_values(ClassMapGenerator::createMap($classmapFullPath));
$result[$compPath][$classmap] = $classes;
yield $compPath => self::getFilteredClasses($compPath, $classMaps, $basePath, $folder, $fileName);
}
}

private static function getFilteredClasses($compPath, $classMapPaths, $basePath, $folder, $fileName)
{
foreach ($classMapPaths as $classmapPath) {
$classes = self::getClasses($compPath, $basePath, $classmapPath);
foreach ($classes as $i => $class) {
if (FilePath::contains(str_replace($basePath, '', $class), $folder, $fileName)) {
unset($classes[$i]);
}
}

yield $classmapPath => $classes;
}
}

private static function getClasses($compPath, $basePath, $classmapPath)
{
$compPath1 = trim($compPath, '/');
$compPath1 = $compPath1 ? $compPath1.DIRECTORY_SEPARATOR : '';
$classmapFullPath = $basePath.DIRECTORY_SEPARATOR.$compPath1.$classmapPath;

return $result;
return array_values(ClassMapGenerator::createMap($classmapFullPath));
}
}
2 changes: 1 addition & 1 deletion src/Features/CheckImports/CheckImportsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function handle()
$folder = rtrim($folder, '/\\');

$routeFiles = FilePath::removeExtraPaths(RoutePaths::get(), $folder, $fileName);
$classMapFiles = ComposerJson::getClassMaps(base_path());
$classMapFiles = ComposerJson::getClassMaps(base_path(), $folder, $fileName);
$autoloadedFiles = FilePath::removeExtraPaths(ComposerJson::autoloadedFilesList(base_path()), $folder, $fileName);

$paramProvider = $this->getParamProvider();
Expand Down
14 changes: 8 additions & 6 deletions src/FileReaders/Paths.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ class Paths
use FiltersFiles;
/**
* @param $dirs
* @param null|string $includeFileName
* @param null|string $includeFolder
* @param null|string $fileName
* @param null|string $folder
* @return \iterable
*/
public static function getAbsFilePaths($dirs, $includeFileName = null, $includeFolder = null)
public static function getAbsFilePaths($dirs, $fileName = null, $folder = null)
{
if (! $dirs) {
return [];
}

$includeFolder && ($includeFolder = str_replace('\\', '/', $includeFolder));
$folder && ($folder = str_replace('\\', '/', $folder));
is_string($dirs) && ($dirs = [$dirs]);
foreach ($dirs as $dir) {
yield $dir => self::filterFiles(self::getPathsInDir($dir, $includeFileName), $includeFolder);
if (is_dir($dir)) {
yield $dir => self::filterFiles(self::getPathsInDir($dir, $fileName), $folder);
}
}
}

Expand All @@ -38,7 +40,7 @@ private static function getPathsInDir($dir, $fileName)
try {
return Finder::create()->files()->name(($fileName ?: '*').'.php')->in($dir);
} catch (Exception $e) {
return Finder::create();
dump($e);
}
}
}
3 changes: 3 additions & 0 deletions src/LaravelPaths/LaravelPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static function migrationDirs()
{
// normalize the migration paths
foreach (app('migrator')->paths() as $path) {
if (! is_dir($path)) {
continue;
}
// Excludes the migrations within "vendor" folder:
if (! Str::startsWith($path, [base_path('vendor')])) {
yield FilePath::normalize($path);
Expand Down

0 comments on commit eea09ff

Please sign in to comment.