-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathForPsr4LoadedClasses.php
45 lines (38 loc) · 1.5 KB
/
ForPsr4LoadedClasses.php
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
<?php
namespace Imanghafoori\LaravelMicroscope;
use Imanghafoori\LaravelMicroscope\Handlers\ErrorExceptionHandler;
use Imanghafoori\LaravelMicroscope\Iterators\CheckSingleMapping;
use Imanghafoori\LaravelMicroscope\Iterators\ChecksOnPsr4Classes;
class ForPsr4LoadedClasses
{
/**
* @param array<class-string<\Imanghafoori\LaravelMicroscope\Iterators\Check>> $checks
* @param array $params
* @param string $includeFile
* @param string $includeFolder
* @return array<string, \Generator>
*/
public static function check($checks, $params = [], $includeFile = '', $includeFolder = '')
{
ChecksOnPsr4Classes::$errorExceptionHandler = ErrorExceptionHandler::class;
$checker = CheckSingleMapping::init($checks, $params, $includeFile, $includeFolder);
return ChecksOnPsr4Classes::apply($checker);
}
public static function checkNow($checks, $params = [], $includeFile = '', $includeFolder = '', $callback = null)
{
self::applyOnStats(
self::check($checks, $params, $includeFile, $includeFolder),
$callback
);
}
public static function applyOnStats(array $allStats, $callback = null)
{
foreach ($allStats as $path => $results) {
foreach (iterator_to_array($results) as $namespace => $result) {
foreach ($result as $folder => $count) {
$callback && $callback($folder, $count, $path, $namespace);
}
}
}
}
}