8000 Extract UtilPrefix to a private static function · symfony/symfony@50fb72f · GitHub
[go: up one dir, main page]

Skip to content

Commit 50fb72f

Browse files
committed
Extract UtilPrefix to a private static function
1 parent cfc79eb commit 50fb72f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class DeprecationErrorHandler
3636
'other' => array(),
3737
'remaining vendor' => array(),
3838
);
39+
private static $utilPrefix = '';
3940

4041
/**
4142
* Registers and configures the deprecation handler.
@@ -56,12 +57,10 @@ public static function register($mode = 0)
5657
return;
5758
}
5859

59-
$UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
60-
61-
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use ($mode, $UtilPrefix) {
60+
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use ($mode) {
6261
$mode = self::getMode($mode);
6362
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || self::MODE_DISABLED === $mode) {
64-
$ErrorHandler = $UtilPrefix.'ErrorHandler';
63+
$ErrorHandler = self::utilPrefix().'ErrorHandler';
6564

6665
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
6766
}
@@ -91,7 +90,7 @@ public static function register($mode = 0)
9190
$method = $trace[$i]['function'];
9291
}
9392

94-
$Test = $UtilPrefix.'Test';
93+
$Test = self::utilPrefix().'Test';
9594

9695
if (0 !== error_reporting()) {
9796
$group = 'unsilenced';
@@ -138,7 +137,7 @@ public static function register($mode = 0)
138137

139138
if (null !== $oldErrorHandler) {
140139
restore_error_handler();
141-
if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) {
140+
if (array(self::utilPrefix().'ErrorHandler', 'handleError') === $oldErrorHandler) {
142141
restore_error_handler();
143142
self::register($mode);
144143
}
@@ -371,4 +370,16 @@ private static function displayDeprecations($groups, $mode)
371370
echo "\n";
372371
}
373372
}
373+
374+
/**
375+
* @return string
376+
*/
377+
private static function utilPrefix()
378+
{
379+
if ('' !== self::$utilPrefix) {
380+
return self::$utilPrefix;
381+
}
382+
383+
return self::$utilPrefix = (class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\');
384+
}
374385
}

0 commit comments

Comments
 (0)
0