@@ -21,7 +21,7 @@ public function timeout(int $timeout): self
2121 return $ this ;
2222 }
2323
24- private function addCheck (Optimizer $ optimizer ): self
24+ public function addCheck (Optimizer $ optimizer ): self
2525 {
2626 if (! in_array ($ optimizer , $ this ->checks ?? [])) {
2727 $ this ->checks [] = $ optimizer ;
@@ -36,19 +36,18 @@ public function run(): Result
3636
3737 collect (Optimizer::cases ())
3838 ->each (
39- function (Optimizer $ optimizer ) use (&$ result ) {
39+ function (Optimizer $ optimizer ) use (&$ result ): bool {
4040
41- if ($ this ->shouldPerformCheck ($ optimizer )) {
42-
43- $ checkResult = $ this -> check ( $ optimizer );
41+ if (! $ this ->shouldPerformCheck ($ optimizer )) {
42+ return true ;
43+ }
4444
45- // phpstan error: Method Lloricode\SpatieImageOptimizerHealthCheck\ImageOptimizerCheck::run() should return Spatie\Health\Checks\Result but returns Spatie\Health\Checks\Result|false.
46- if (! is_bool ($ checkResult )) {
45+ $ checkResult = $ this ->check ($ optimizer );
4746
48- $ result = $ checkResult ;
47+ if ($ checkResult !== true ) {
48+ $ result = $ checkResult ;
4949
50- return false ;
51- }
50+ return false ;
5251 }
5352
5453 return true ;
@@ -58,7 +57,7 @@ function (Optimizer $optimizer) use (&$result) {
5857 return $ result ;
5958 }
6059
61- private function check (Optimizer $ optimizer ): Result |bool // TODO: remove `bool` then use ` true` on php 8.2
60+ private function check (Optimizer $ optimizer ): Result |true
6261 {
6362 $ process = Process::timeout ($ this ->timeout )
6463 ->run ($ optimizer ->command ());
@@ -73,39 +72,43 @@ private function check(Optimizer $optimizer): Result|bool // TODO: remove `bool`
7372 private function shouldPerformCheck (Optimizer $ optimizer ): bool
7473 {
7574 if ($ this ->checks === null ) {
76- // ray($optimizer)->green();
7775 return true ;
7876 }
79- // ray($optimizer)->orange();
8077
8178 return in_array ($ optimizer , $ this ->checks );
8279 }
8380
81+ /** @deprecated use addCheck() will be removed on v3 */
8482 public function checkJPEGOPTIM (): self
8583 {
8684 return $ this ->addCheck (Optimizer::JPEGOPTIM );
8785 }
8886
87+ /** @deprecated use addCheck() will be removed on v3 */
8988 public function checkOPTIPNG (): self
9089 {
9190 return $ this ->addCheck (Optimizer::OPTIPNG );
9291 }
9392
93+ /** @deprecated use addCheck() will be removed on v3 */
9494 public function checkPNGQUANT (): self
9595 {
9696 return $ this ->addCheck (Optimizer::PNGQUANT );
9797 }
9898
99+ /** @deprecated use addCheck() will be removed on v3 */
99100 public function checkSVGO (): self
100101 {
101102 return $ this ->addCheck (Optimizer::SVGO );
102103 }
103104
105+ /** @deprecated use addCheck() will be removed on v3 */
104106 public function checkGIFSICLE (): self
105107 {
106108 return $ this ->addCheck (Optimizer::GIFSICLE );
107109 }
108110
111+ /** @deprecated use addCheck() will be removed on v3 */
109112 public function checkWEBP (): self
110113 {
111114 return $ this ->addCheck (Optimizer::WEBP );
0 commit comments