19
19
class DeprecationErrorHandler
20
20
{
21
21
const MODE_WEAK = 'weak ' ;
22
+ const MODE_WEAK_VENDORS = 'weak_vendors ' ;
22
23
const MODE_DISABLED = 'disabled ' ;
23
24
24
25
private static $ isRegistered = false ;
@@ -28,6 +29,7 @@ class DeprecationErrorHandler
28
29
*
29
30
* The following reporting modes are supported:
30
31
* - use "weak" to hide the deprecation report but keep a global count;
32
+ * - use "weak_vendors" to act as "weak" but only for vendors;
31
33
* - use "/some-regexp/" to stop the test suite whenever a deprecation
32
34
* message matches the given regular expression;
33
35
* - use a number to define the upper bound of allowed deprecations,
@@ -50,7 +52,10 @@ public static function register($mode = 0)
50
52
if (false === $ mode ) {
51
53
$ mode = getenv ('SYMFONY_DEPRECATIONS_HELPER ' );
52
54
}
53
- if (DeprecationErrorHandler::MODE_WEAK !== $ mode && (!isset ($ mode [0 ]) || '/ ' !== $ mode [0 ])) {
55
+ if (!in_array ($ mode , array (
56
+ DeprecationErrorHandler::MODE_WEAK ,
57
+ DeprecationErrorHandler::MODE_WEAK_VENDORS
58
+ )) && (!isset ($ mode [0 ]) || '/ ' !== $ mode [0 ])) {
54
59
$ mode = preg_match ('/^[1-9][0-9]*$/ ' , $ mode ) ? (int ) $ mode : 0 ;
55
60
}
56
61
@@ -67,6 +72,12 @@ public static function register($mode = 0)
67
72
'legacy ' => array (),
68
73
'other ' => array (),
69
74
);
75
+ if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $ mode ) {
76
+ $ deprecations += array (
77
+ 'remaining vendorCount ' => 0 ,
78
+ 'remaining vendor ' => array (),
79
+ );
80
+ }
70
81
$ deprecationHandler = function ($ type , $ msg , $ file , $ line , $ context ) use (&$ deprecations , $ getMode ) {
71
82
$ mode = $ getMode ();
72
83
if ((E_USER_DEPRECATED !== $ type && E_DEPRECATED !== $ type ) || DeprecationErrorHandler::MODE_DISABLED === $ mode ) {
@@ -76,6 +87,10 @@ public static function register($mode = 0)
76
87
$ trace = debug_backtrace (true );
77
88
$ group = 'other ' ;
78
89
90
+ $ isVendor = (strpos ($ file , '/vendor/ ' ) !== false );
91
+ $ isWeak = DeprecationErrorHandler::MODE_WEAK === $ mode ||
92
+ DeprecationErrorHandler::MODE_WEAK_VENDORS === $ mode && $ isVendor ;
93
+
79
94
$ i = count ($ trace );
80
95
while (1 < $ i && (!isset ($ trace [--$ i ]['class ' ]) || ('ReflectionMethod ' === $ trace [$ i ]['class ' ] || 0 === strpos ($ trace [$ i ]['class ' ], 'PHPUnit_ ' )))) {
81
96
// No-op
@@ -94,6 +109,8 @@ public static function register($mode = 0)
94
109
|| in_array ('legacy ' , \PHPUnit_Util_Test::getGroups ($ class , $ method ), true )
95
110
) {
96
111
$ group = 'legacy ' ;
112
+ } elseif (DeprecationErrorHandler::MODE_WEAK_VENDORS === $ mode && $ isVendor ) {
113
+ $ group = 'remaining vendor ' ;
97
114
} else {
98
115
$ group = 'remaining ' ;
99
116
}
@@ -112,13 +129,13 @@ public static function register($mode = 0)
112
129
113
130
exit (1 );
114
131
}
115
- if ('legacy ' !== $ group && DeprecationErrorHandler:: MODE_WEAK !== $ mode ) {
132
+ if ('legacy ' !== $ group && ! $ isWeak ) {
116
133
$ ref = &$ deprecations [$ group ][$ msg ]['count ' ];
117
134
++$ ref ;
118
135
$ ref = &$ deprecations [$ group ][$ msg ][$ class .':: ' .$ method ];
119
136
++$ ref ;
120
137
}
121
- } elseif (DeprecationErrorHandler:: MODE_WEAK !== $ mode ) {
138
+ } elseif (! $ isWeak ) {
122
139
$ ref = &$ deprecations [$ group ][$ msg ]['count ' ];
123
140
++$ ref ;
124
141
}
@@ -162,9 +179,15 @@ public static function register($mode = 0)
162
179
return $ b ['count ' ] - $ a ['count ' ];
163
180
};
164
181
165
- foreach (array ('unsilenced ' , 'remaining ' , 'legacy ' , 'other ' ) as $ group ) {
182
+ $ groups = array ('unsilenced ' , 'remaining ' );
183
+ if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $ mode ) {
184
+ $ groups [] = 'remaining vendor ' ;
185
+ }
186
+ array_push ($ groups , 'legacy ' , 'other ' );
187
+
188
+ foreach ($ groups as $ group ) {
166
189
if ($ deprecations [$ group .'Count ' ]) {
167
- echo "\n" , $ colorize (sprintf ('%s deprecation notices (%d) ' , ucfirst ($ group ), $ deprecations [$ group .'Count ' ]), 'legacy ' !== $ group ), "\n" ;
190
+ echo "\n" , $ colorize (sprintf ('%s deprecation notices (%d) ' , ucfirst ($ group ), $ deprecations [$ group .'Count ' ]), ! in_array ( $ group , array ( 'legacy ' , ' remaining vendor ' ), true ) ), "\n" ;
168
191
169
192
uasort ($ deprecations [$ group ], $ cmp );
170
193
0 commit comments