@@ -21,43 +21,63 @@ class SelfDiagnosisCommand extends Command
2121 */
2222 protected $ description = 'Perform application self diagnosis. ' ;
2323
24+ private $ messages = [];
25+
2426 public function handle ()
2527 {
26- $ checks = config ('self-diagnosis.checks ' );
28+ $ this ->runChecks (config ('self-diagnosis.checks ' , []), 'Running Common Checks ' );
29+
30+ $ environmentChecks = config ('self-diagnosis.development ' , []);
31+ if (in_array (app ()->environment (), config ('self-diagnosis.productionEnvironments ' ))) {
32+ $ environmentChecks = config ('self-diagnosis.production ' , []);
33+ }
34+
35+ $ this ->runChecks ($ environmentChecks , 'Environment Specific Checks ( ' .app ()->environment ().') ' );
36+
37+ if (count ($ this ->messages )) {
38+ $ this ->output ->writeln ('The following checks failed: ' );
39+
40+ foreach ($ this ->messages as $ message ) {
41+ $ this ->output ->writeln ('<fg=red> ' .$ message .'</fg=red> ' );
42+ $ this ->output ->writeln ('' );
43+ }
44+ } else {
45+ $ this ->info ('Good job, looks like you are all set up. ' );
46+ }
47+ }
2748
49+ protected function runChecks (array $ checks , string $ title )
50+ {
2851 $ max = count ($ checks );
2952 $ current = 1 ;
30- $ messages = [];
53+
54+ $ this ->output ->writeln ('|------------------------------------- ' );
55+ $ this ->output ->writeln ('| ' .$ title );
56+ $ this ->output ->writeln ('|------------------------------------- ' );
3157
3258 foreach ($ checks as $ check ) {
33- /** @var Check $checkClass */
3459 $ checkClass = app ($ check );
3560
3661 $ this ->output ->write ("<fg=yellow>Running check {$ current }/ {$ max }:</fg=yellow> {$ checkClass ->name ()}... " );
3762
38- if ($ checkClass ->check ()) {
39- $ this ->output ->write ('<fg=green>✔</fg=green> ' );
40- } else {
41- $ this ->output ->write ('<fg=red>✘</fg=red> ' );
42-
43- $ messages [] = $ checkClass ->message ();
44- }
63+ $ this ->runCheck ($ checkClass );
4564
46- $ this ->output ->write (PHP_EOL );
4765 $ current ++;
4866 }
4967
5068 $ this ->output ->writeln ('' );
69+ }
5170
52- if (count ($ messages )) {
53- $ this ->output ->writeln ('The following checks failed: ' );
54-
55- foreach ($ messages as $ message ) {
56- $ this ->output ->writeln ('<fg=red> ' .$ message .'</fg=red> ' );
57- $ this ->output ->writeln ('' );
58- }
71+ protected function runCheck (Check $ check )
72+ {
73+ if ($ check ->check ()) {
74+ $ this ->output ->write ('<fg=green>✔</fg=green> ' );
5975 } else {
60- $ this ->info ('Good job, looks like you are all set up. ' );
76+ $ this ->output ->write ('<fg=red>✘</fg=red> ' );
77+
78+ $ this ->messages [] = $ check ->message ();
6179 }
80+
81+ $ this ->output ->write (PHP_EOL );
6282 }
6383}
0 commit comments