1616use Throwable ;
1717
1818use function __ ;
19+ use function array_filter ;
1920use function array_splice ;
2021use function count ;
2122use function defined ;
4445 */
4546class ErrorHandler
4647{
47- public static self |null $ instance = null ;
48+ private static self |null $ instance = null ;
4849
4950 /**
5051 * holds errors to be displayed or reported later ...
@@ -343,7 +344,7 @@ public function dispUserErrors(): void
343344 /**
344345 * Renders user errors not displayed
345346 */
346- public function getDispUserErrors (): string
347+ private function getDispUserErrors (): string
347348 {
348349 $ retval = '' ;
349350 foreach ($ this ->getErrors () as $ error ) {
@@ -377,9 +378,7 @@ public function getDispErrors(): string
377378 $ retval .= $ this ->getDispUserErrors ();
378379 }
379380
380- // if preference is not 'never' and
381- // there are 'actual' errors to be reported
382- if ($ config ->settings ['SendErrorReports ' ] !== 'never ' && $ this ->countErrors () !== $ this ->countUserErrors ()) {
381+ if ($ config ->settings ['SendErrorReports ' ] !== 'never ' && $ this ->countActualErrors () !== 0 ) {
383382 // add report button.
384383 $ retval .= '<form method="post" action=" ' . Url::getFromRoute ('/error-report ' )
385384 . '" id="pma_report_errors_form" ' ;
@@ -422,7 +421,7 @@ public function getDispErrors(): string
422421 /**
423422 * look in session for saved errors
424423 */
425- protected function checkSavedErrors (): void
424+ private function checkSavedErrors (): void
426425 {
427426 if (! isset ($ _SESSION ['errors ' ])) {
428427 return ;
@@ -454,63 +453,26 @@ public function countErrors(bool $check = true): int
454453 return count ($ this ->getErrors ($ check ));
455454 }
456455
457- /**
458- * return count of user errors
459- *
460- * @return int number of user errors occurred
461- */
462456 public function countUserErrors (): int
463457 {
464- $ count = 0 ;
465- if ($ this ->countErrors () !== 0 ) {
466- foreach ($ this ->getErrors () as $ error ) {
467- if (! $ error ->isUserError ()) {
468- continue ;
469- }
470-
471- $ count ++;
472- }
473- }
474-
475- return $ count ;
458+ return count (array_filter ($ this ->getErrors (), static fn (Error $ error ): bool => $ error ->isUserError ()));
476459 }
477460
478- /**
479- * whether use errors occurred or not
480- */
481- public function hasUserErrors (): bool
461+ private function countActualErrors (): int
482462 {
483- return ( bool ) $ this -> countUserErrors ( );
463+ return count ( array_filter ( $ this -> getErrors (), static fn ( Error $ error ): bool => ! $ error -> isUserError ()) );
484464 }
485465
486466 /**
487- * whether errors occurred or not
488- */
489- public function hasErrors (): bool
490- {
491- return (bool ) $ this ->countErrors ();
492- }
493-
494- /**
495- * number of errors to be displayed
496- *
497- * @return int number of errors to be displayed
467+ * whether there are errors to display or not
498468 */
499- public function countDisplayErrors (): int
469+ public function hasDisplayErrors (): bool
500470 {
501471 if (Config::getInstance ()->settings ['SendErrorReports ' ] !== 'never ' ) {
502- return $ this ->countErrors () ;
472+ return $ this ->getErrors () !== [] ;
503473 }
504474
505- return $ this ->countUserErrors ();
506- }
507-
508- /**
509- * whether there are errors to display or not
510- */
511- public function hasDisplayErrors (): bool
512- {
513- return (bool ) $ this ->countDisplayErrors ();
475+ return $ this ->countUserErrors () !== 0 ;
514476 }
515477
516478 /**
@@ -534,7 +496,7 @@ public function savePreviousErrors(): void
534496 public function hasErrorsForPrompt (): bool
535497 {
536498 return Config::getInstance ()->settings ['SendErrorReports ' ] !== 'never '
537- && $ this ->countErrors () !== $ this -> countUserErrors () ;
499+ && $ this ->countActualErrors () !== 0 ;
538500 }
539501
540502 /**
@@ -544,9 +506,7 @@ public function hasErrorsForPrompt(): bool
544506 */
545507 public function reportErrors (): void
546508 {
547- // if there're no actual errors,
548- if (! $ this ->hasErrors () || $ this ->countErrors () === $ this ->countUserErrors ()) {
549- // then simply return.
509+ if ($ this ->getErrors () === [] || $ this ->countActualErrors () === 0 ) {
550510 return ;
551511 }
552512
0 commit comments