11<?php
22
3- /**
4- * This program is free software; you can redistribute it and/or modify
5- * it under the terms of the GNU General Public License as published by
6- * the Free Software Foundation; either version 2 of the License, or
7- * (at your option) any later version.
8- *
9- * This program is distributed in the hope that it will be useful,
10- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12- * GNU General Public License for more details.
13- *
14- * You should have received a copy of the GNU General Public License along
15- * with this program; if not, write to the Free Software Foundation, Inc.,
16- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17- * http://www.gnu.org/copyleft/gpl.html
18- *
19- * @file
20- */
21-
223namespace Base \Debug ;
234
24- class AtEase {
5+ class AtEase
6+ {
7+
8+ private static int $ suppressCount = 0 ;
259
26- private static $ suppressCount = 0 ;
27- private static $ originalLevel = false ;
10+ private static bool $ originalLevel = false ;
2811
2912 /**
3013 * Reference-counted warning suppression
3114 *
3215 * @param bool $end Whether to restore warnings
3316 */
34- public static function suppressWarnings ( $ end = false ) {
17+ public static function suppressWarnings ( bool $ end = false ): void
18+ {
3519 if ( $ end ) {
20+
3621 if ( self ::$ suppressCount ) {
22+
3723 --self ::$ suppressCount ;
3824 if ( !self ::$ suppressCount ) {
3925 error_reporting ( self ::$ originalLevel );
4026 }
27+
4128 }
29+
4230 } else {
31+
4332 if ( !self ::$ suppressCount ) {
4433 self ::$ originalLevel =
4534 error_reporting ( E_ALL & ~(
@@ -52,14 +41,16 @@ public static function suppressWarnings( $end = false ) {
5241 E_STRICT
5342 ) );
5443 }
44+
5545 ++self ::$ suppressCount ;
5646 }
5747 }
5848
5949 /**
6050 * Restore error level to previous value
6151 */
62- public static function restoreWarnings () {
52+ public static function restoreWarnings (): void
53+ {
6354 self ::suppressWarnings ( true );
6455 }
6556
@@ -70,13 +61,16 @@ public static function restoreWarnings() {
7061 * @param mixed ...$args Optional arguments for the function call
7162 * @return mixed
7263 */
73- public static function quietCall ( callable $ callback , ...$ args ) {
64+ public static function quietCall ( callable $ callback , ...$ args )
65+ {
7466 self ::suppressWarnings ();
67+
7568 try {
7669 $ rv = $ callback ( ...$ args );
7770 } finally {
7871 self ::restoreWarnings ();
7972 }
73+
8074 return $ rv ;
8175 }
8276
0 commit comments