-
Notifications
You must be signed in to change notification settings - Fork 1
/
OptimizationCheck.php
82 lines (68 loc) · 1.85 KB
/
OptimizationCheck.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Appkeep\Laravel\Checks;
use Appkeep\Laravel\Check;
use Appkeep\Laravel\Result;
use Illuminate\Support\Str;
class OptimizationCheck extends Check
{
private static $checks = [
'routesAreCached',
'configIsCached',
'eventsAreCached',
'servicesAreCached',
'packagesAreCached',
];
public function run()
{
$output = collect([]);
foreach (static::$checks as $check) {
$output->put(
$check,
call_user_func([$this, $check])
);
}
$failing = $output->where(null, false);
// All optimizations are done!
if ($failing->isEmpty()) {
return Result::ok();
}
$title = sprintf(
'Missing %d %s',
$failing->count(),
Str::plural('optimization', $failing->count())
);
return Result::warn($title)
->message(
'Missing optimizations: ' .
$failing->keys()
->map(
fn ($check) => (string) Str::of($check)
->snake()
->replace('_', ' ')
->ucfirst()
->words(1, '')
)
->join(', ')
);
}
private function routesAreCached()
{
return app()->routesAreCached();
}
private function configIsCached()
{
return app()->configurationIsCached();
}
private function eventsAreCached()
{
return app()->eventsAreCached();
}
private function servicesAreCached()
{
return file_exists(app()->getCachedServicesPath());
}
private function packagesAreCached()
{
return file_exists(app()->getCachedPackagesPath());
}
}