-
Notifications
You must be signed in to change notification settings - Fork 97
/
microscope
61 lines (47 loc) · 2.1 KB
/
microscope
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter;
use Imanghafoori\LaravelMicroscope\Features\CheckImports\Checks\CheckClassReferencesAreValid;
use Imanghafoori\LaravelMicroscope\Features\CheckImports\Handlers\PrintWrongClassRefs;
use Imanghafoori\LaravelMicroscope\Features\CheckImports\Reporters\CheckImportReporter;
use Imanghafoori\LaravelMicroscope\Features\CheckImports\Reporters\Psr4Report;
use Imanghafoori\LaravelMicroscope\FileReaders\FilePath;
use Imanghafoori\LaravelMicroscope\ForPsr4LoadedClasses;
use Imanghafoori\TokenAnalyzer\ParseUseStatement;
use Symfony\Component\Console\Output\ConsoleOutput;
if (isset($GLOBALS['_composer_autoload_path'])) {
define('COMPOSER_INSTALL', $GLOBALS['_composer_autoload_path']);
unset($GLOBALS['_composer_autoload_path']);
} else {
foreach ([__DIR__.'/../../autoload.php', __DIR__.'/../vendor/autoload.php', __DIR__.'/vendor/autoload.php'] as $file) {
if (file_exists($file)) {
define('COMPOSER_INSTALL', $file);
break;
}
}
unset($file);
}
require_once base_path().'\vendor\autoload.php';
require_once COMPOSER_INSTALL;
\Imanghafoori\LaravelMicroscope\Analyzers\ComposerJson::$composer = function () {
$comp = FilePath::$basePath = base_path();
return \ImanGhafoori\ComposerJson\ComposerJson::make($comp);
};
function base_path() {
if (file_exists(getcwd().'/../../../composer.json')) {
$comp = getcwd().'/../../..';
} elseif (file_exists(getcwd().'/composer.json')) {
// for dev
$comp = getcwd();
}
return $comp;
}
CheckClassReferencesAreValid::$wrongClassRefsHandler = PrintWrongClassRefs::class;
$psr4Stats = ForPsr4LoadedClasses::check([CheckClassReferencesAreValid::class], function ($tokens) {
$imports = ParseUseStatement::parseUseStatements($tokens);
return $imports[0] ?: [$imports[1]];
});
$output = new ConsoleOutput();
ErrorPrinter::singleton($output)->logErrors();
$output->writeln(CheckImportReporter::totalImportsMsg(1));
$output->writeln(Psr4Report::printPsr4($psr4Stats));
//$output->writeln(CheckImportReporter::printErrorsCount());