@@ -20,13 +20,19 @@ class DeprecationErrorHandler
20
20
if (self::$isRegistered) {
21
21
return;
22
22
}
23
- $deprecations = array(0);
24
- $oldErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context) use (&$deprecations) {
23
+ $deprecations = array(
24
+ 'remainingCount' => 0,
25
+ 'legacyCount' => 0,
26
+ 'otherCount' => 0,
27
+ 'remaining' => array(),
28
+ 'legacy' => array(),
29
+ 'other' => array(),
30
+ );
31
+ $deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations) {
25
32
if (E_USER_DEPRECATED !== $type) {
26
33
return PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
27
34
}
28
35
29
- ++$deprecations[0];
30
36
$trace = debug_backtrace(PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false);
31
37
32
38
$i = count($trace);
@@ -35,13 +41,24 @@ class DeprecationErrorHandler
35
41
}
36
42
37
43
if (isset($trace[$i]['class'])) {
38
- if (isset($deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg])) {
39
- ++$deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg];
44
+ $class = $trace[$i]['class'];
45
+ $method = $trace[$i]['function'];
46
+
47
+ $type = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || strpos($class, '\Legacy') ? 'legacy' : 'remaining';
48
+
49
+ if ('legacy' === $type && 0 === (error_reporting() & E_USER_DEPRECATED)) {
50
+ @++$deprecations[$type]['Silenced']['count'];
40
51
} else {
41
- $deprecations[$trace[$i]['class']][$trace[$i]['function']][$msg] = 1;
52
+ @++$deprecations[$type][$msg]['count'];
53
+ @++$deprecations[$type][$msg][$class.'::'.$method];
42
54
}
55
+ } else {
56
+ $type = 'other';
57
+ @++$deprecations[$type][$msg]['count'];
43
58
}
44
- });
59
+ ++$deprecations[$type.'Count'];
60
+ };
61
+ $oldErrorHandler = set_error_handler($deprecationHandler);
45
62
46
63
if (null !== $oldErrorHandler) {
47
64
restore_error_handler();
@@ -51,31 +68,52 @@ class DeprecationErrorHandler
51
68
}
52
69
} else {
53
70
self::$isRegistered = true;
54
- register_shutdown_function(function () use (&$deprecations) {
55
- if ($deprecations[0]) {
56
- if (function_exists('posix_isatty') && @posix_isatty(STDOUT)) {
57
- echo "\n\x1B[43;30mDeprecation notices ($deprecations[0]):\x1B[0m\n";
58
- } else {
59
- echo "\nDeprecation notices ($deprecations[0]):\n";
60
- }
71
+ register_shutdown_function(function () use (&$deprecations, $deprecationHandler) {
72
+
73
+ $colorize = new \SebastianBergmann\Environment\Console();
74
+
75
+ if ($colorize->hasColorSupport()) {
76
+ $colorize = function ($str, $red) {
77
+ $color = $red ? '41;37' : '43;30';
78
+
79
+ return "\x1B[{$color}m{$str}\x1B[0m";
80
+ };
81
+ } else {
82
+ $colorize = function ($str) {return $str;};
83
+ }
84
+
85
+ $currErrorHandler = set_error_handler('var_dump');
86
+ restore_error_handler();
61
87
62
- foreach ($deprecations as $class => $notices) {
63
- if (0 !== $class) {
64
- echo "\n{$class}\n";
65
- foreach ($notices as $method => $notices) {
66
- echo " ->{$method}()\n";
67
- foreach ($notices as $msg => $freq) {
68
- echo " {$msg}: $freq\n";
88
+ if ($currErrorHandler !== $deprecationHandler) {
89
+ echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
90
+ }
91
+
92
+ $cmp = function ($a, $b) {
93
+ return $b['count'] - $a['count'];
94
+ };
95
+
96
+ foreach (array('remaining', 'legacy', 'other') as $type) {
97
+ if ($deprecations[$type]) {
98
+ echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($type), $deprecations[$type.'Count']), 'legacy' !== $type), "\n";
99
+
100
+ uasort($deprecations[$type], $cmp);
101
+
102
+ foreach ($deprecations[$type] as $msg => $notices) {
103
+ echo "\n", $msg, ': ', $notices['count'], "x\n";
104
+
105
+ arsort($notices);
106
+
107
+ foreach ($notices as $method => $count) {
108
+ if ('count' !== $method) {
109
+ echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
69
110
}
70
111
}
71
112
}
72
113
}
73
- } else {
74
- if (function_exists('posix_isatty') && @posix_isatty(STDOUT)) {
75
- echo "\n\x1B[42;30mNo deprecation notice\x1B[0m\n";
76
- } else {
77
- echo "\nNo deprecation notice\n";
78
- }
114
+ }
115
+ if (!empty($notices)) {
116
+ echo "\n";
79
117
}
80
118
});
81
119
}
0 commit comments