Skip to content

Commit 613f726

Browse files
committed
refactor
1 parent 5375273 commit 613f726

File tree

7 files changed

+12
-30
lines changed

7 files changed

+12
-30
lines changed

src/Features/CheckImports/Checks/CheckClassAtMethod.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ public static function check(PhpFileDescriptor $file)
1616
{
1717
$tokens = $file->getTokens();
1818

19-
$replaced = self::$handler::handle(
20-
$file,
21-
self::getAtSignTokens($tokens)
22-
);
23-
24-
if ($replaced) {
25-
return $file->getTokens(true);
26-
}
19+
self::$handler::handle($file, self::getAtSignTokens($tokens));
2720
}
2821

2922
#[Pure]

src/Features/CheckImports/Checks/CheckClassReferencesAreValid.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ public static function check(PhpFileDescriptor $file)
4343
[$extraWrongImports] = ImportsAnalyzer::filterWrongClassRefs($extraImports, $absFilePath);
4444

4545
$wrongClassRefs = array_merge($wrongClassRefs, $wrongDocblockRefs);
46-
$tokens = null;
46+
4747
if ($wrongClassRefs && self::$checkWrong && self::$wrongClassRefsHandler) {
48-
[$tokens, $isFixed] = self::$wrongClassRefsHandler::handle(
48+
$isFixed = self::$wrongClassRefsHandler::handle(
4949
$wrongClassRefs,
5050
$file,
5151
$hostNamespace,
52-
$file->getTokens(),
5352
);
5453

5554
if ($isFixed) {
@@ -60,7 +59,5 @@ public static function check(PhpFileDescriptor $file)
6059
// Extra wrong imports:
6160
$handler = self::$extraWrongImportsHandler;
6261
$handler && $handler::handle($extraWrongImports, $file);
63-
64-
return $tokens;
6562
}
6663
}

src/Features/CheckImports/Handlers/FixWrongClassRefs.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
*/
1414
class FixWrongClassRefs
1515
{
16-
public static function handle(array $wrongClassRefs, PhpFileDescriptor $file, $hostNamespace, array $tokens): array
16+
public static function handle(array $wrongClassRefs, PhpFileDescriptor $file, $hostNamespace): bool
1717
{
18-
$printer = ErrorPrinter::singleton();
19-
2018
foreach ($wrongClassRefs as $classReference) {
2119
$wrongClassRef = $classReference['class'];
2220
$line = $classReference['line'];
@@ -39,15 +37,9 @@ public static function handle(array $wrongClassRefs, PhpFileDescriptor $file, $h
3937
} else {
4038
WrongImportHandler::handle($wrongClassRef, $file, $line);
4139
}
42-
43-
if ($isFixed) {
44-
$tokens = token_get_all($afterFix);
45-
46-
return [$tokens, true];
47-
}
4840
}
4941

50-
return [$tokens, false];
42+
return false;
5143
}
5244

5345
private static function fixClassReference($file, $class, $line, $namespace)

src/Foundations/Analyzers/Fixer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Imanghafoori\LaravelMicroscope\Foundations\Analyzers;
44

55
use ImanGhafoori\ComposerJson\NamespaceCalculator;
6-
use Imanghafoori\Filesystem\FileManipulator;
76
use Imanghafoori\LaravelMicroscope\Foundations\ClassListProvider;
87
use Imanghafoori\LaravelMicroscope\Foundations\Loop;
98
use Imanghafoori\LaravelMicroscope\Foundations\PhpFileDescriptor;
@@ -93,7 +92,7 @@ public static function fixReference(PhpFileDescriptor $file, $inlinedClassRef, $
9392
}
9493

9594
return [
96-
FileManipulator::insertNewLine($file->getAbsolutePath(), "use $fullClassPath;", $lineNum),
95+
$file->insertNewLine("use $fullClassPath;", $lineNum),
9796
$correct,
9897
];
9998
}

src/Foundations/Iterators/CheckSet.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ private function performCheck($check, PhpFileDescriptor $file)
125125
private function applyCheck($check, PhpFileDescriptor $file): void
126126
{
127127
try {
128-
$newTokens = $this->performCheck($check, $file);
129-
$newTokens && $file->setTokens($newTokens);
128+
$this->performCheck($check, $file);
130129
} catch (Throwable $exception) {
131130
$this->exceptions[] = $exception;
132131
}

src/Foundations/PhpFileDescriptor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ public static function searchReplace($search, $replace, $tokens): array
174174

175175
public function insertNewLine($newLine, $atLine)
176176
{
177+
$this->tokens = [];
178+
177179
return FileManipulator::insertNewLine($this->getAbsolutePath(), $newLine, $atLine);
178180
}
179181

src/Foundations/Reports/RouteReport.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class RouteReport
1010
{
1111
/**
1212
* @param \Imanghafoori\LaravelMicroscope\Foundations\Iterators\DTO\FilesDto $routeFiles
13-
* @return string
13+
* @return array
1414
*/
1515
#[Pure]
1616
public static function getStats($routeFiles)
1717
{
1818
$lines = CheckImportReporter::formatFiles($routeFiles);
1919
$count = count($lines);
2020
$s = $count <= 1 ? '' : 's';
21-
$count = Color::white("($count files)");
21+
$countStr = Color::white("($count files)");
2222

23-
return [CheckImportReporter::hyphen()."route$s {$count}", $lines];
23+
return [CheckImportReporter::hyphen()."route$s {$countStr}", $lines];
2424
}
2525
}

0 commit comments

Comments
 (0)