Skip to content

Commit

Permalink
Rely on memoized variable
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Dec 30, 2018
1 parent 50fb72f commit 14cd6d6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public static function register($mode = 0)
return;
}

$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use ($mode) {
$mode = self::getMode($mode);
self::computeMode($mode);

$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) {
$mode = self::$mode;
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || self::MODE_DISABLED === $mode) {
$ErrorHandler = self::utilPrefix().'ErrorHandler';

Expand Down Expand Up @@ -143,8 +145,8 @@ public static function register($mode = 0)
}
} else {
self::$isRegistered = true;
register_shutdown_function(function () use ($mode, $deprecationHandler) {
$mode = self::getMode($mode);
register_shutdown_function(function () use ($deprecationHandler) {
$mode = self::$mode;
if (isset($mode[0]) && '/' === $mode[0]) {
return;
}
Expand Down Expand Up @@ -251,13 +253,11 @@ private static function hasColorSupport()

/**
* @param mixed $mode
*
* @return mixed
*/
private static function getMode($mode)
private static function computeMode($mode)
{
if (false !== self::$mode) {
return self::$mode;
return;
}
if (false === $mode) {
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
Expand All @@ -270,7 +270,7 @@ private static function getMode($mode)
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
}

return self::$mode = $mode;
self::$mode = $mode;
}

/**
Expand Down

0 comments on commit 14cd6d6

Please sign in to comment.