@@ -39,43 +39,50 @@ public function formatErrors(
3939 if (!$ fileSpecificError ->canBeIgnored ()) {
4040 continue ;
4141 }
42- $ fileErrors ['/ ' . $ this ->relativePathHelper ->getRelativePath ($ fileSpecificError ->getFilePath ())][] = $ fileSpecificError ;
42+ $ traitFilePath = $ fileSpecificError ->getTraitFilePath ();
43+ $ fileErrors ['/ ' . $ this ->relativePathHelper ->getRelativePath ($ fileSpecificError ->getFilePath ())][] = [
44+ 'error ' => $ fileSpecificError ,
45+ 'origin ' => $ traitFilePath !== null ? '/ ' . $ this ->relativePathHelper ->getRelativePath ($ traitFilePath ) : null ,
46+ ];
4347 }
4448 ksort ($ fileErrors , SORT_STRING );
4549
4650 $ php = '<?php declare(strict_types = 1); ' ;
4751 $ php .= "\n\n" ;
4852 $ php .= '$ignoreErrors = []; ' ;
4953 $ php .= "\n" ;
50- foreach ($ fileErrors as $ file => $ errors ) {
51- $ fileErrorsByMessage = [];
52- foreach ($ errors as $ error ) {
54+ foreach ($ fileErrors as $ file => $ fileErrorEntries ) {
55+ $ fileErrorsByKey = [];
56+ foreach ($ fileErrorEntries as [ ' error ' => $ error, ' origin ' => $ origin ] ) {
5357 $ errorMessage = $ error ->getMessage ();
5458 $ identifier = $ error ->getIdentifier ();
55- if (!isset ($ fileErrorsByMessage [$ errorMessage ])) {
56- $ fileErrorsByMessage [$ errorMessage ] = [
57- 1 ,
58- $ identifier !== null ? [$ identifier => 1 ] : [],
59+ $ key = $ errorMessage . "\0" . ($ origin ?? '' );
60+ if (!isset ($ fileErrorsByKey [$ key ])) {
61+ $ fileErrorsByKey [$ key ] = [
62+ 'message ' => $ errorMessage ,
63+ 'origin ' => $ origin ,
64+ 'count ' => 1 ,
65+ 'identifiers ' => $ identifier !== null ? [$ identifier => 1 ] : [],
5966 ];
6067 continue ;
6168 }
6269
63- $ fileErrorsByMessage [ $ errorMessage ][ 0 ]++;
70+ $ fileErrorsByKey [ $ key ][ ' count ' ]++;
6471
6572 if ($ identifier === null ) {
6673 continue ;
6774 }
6875
69- if (!isset ($ fileErrorsByMessage [ $ errorMessage ][ 1 ][$ identifier ])) {
70- $ fileErrorsByMessage [ $ errorMessage ][ 1 ][$ identifier ] = 1 ;
76+ if (!isset ($ fileErrorsByKey [ $ key ][ ' identifiers ' ][$ identifier ])) {
77+ $ fileErrorsByKey [ $ key ][ ' identifiers ' ][$ identifier ] = 1 ;
7178 continue ;
7279 }
7380
74- $ fileErrorsByMessage [ $ errorMessage ][ 1 ][$ identifier ]++;
81+ $ fileErrorsByKey [ $ key ][ ' identifiers ' ][$ identifier ]++;
7582 }
76- ksort ($ fileErrorsByMessage , SORT_STRING );
83+ ksort ($ fileErrorsByKey , SORT_STRING );
7784
78- foreach ($ fileErrorsByMessage as $ message => [ $ totalCount , $ identifiers ]) {
85+ foreach ($ fileErrorsByKey as [ ' message ' => $ message, ' origin ' => $ origin , ' count ' => $ totalCount , ' identifiers ' => $ identifiers ]) {
7986 if ($ this ->useRawMessage ) {
8087 $ messageKey = 'rawMessage ' ;
8188 } else {
@@ -86,23 +93,46 @@ public function formatErrors(
8693 ksort ($ identifiers , SORT_STRING );
8794 if (count ($ identifiers ) > 0 ) {
8895 foreach ($ identifiers as $ identifier => $ identifierCount ) {
96+ if ($ origin !== null ) {
97+ $ php .= sprintf (
98+ "\$ignoreErrors[] = [ \n\t%s => %s, \n\t'identifier' => %s, \n\t'count' => %s, \n\t'path' => __DIR__ . %s, \n\t'origin' => __DIR__ . %s, \n]; \n" ,
99+ var_export ($ messageKey , true ),
100+ var_export (Helpers::escape ($ message ), true ),
101+ var_export (Helpers::escape ($ identifier ), true ),
102+ var_export ($ identifierCount , true ),
103+ var_export (Helpers::escape ($ file ), true ),
104+ var_export (Helpers::escape ($ origin ), true ),
105+ );
106+ } else {
107+ $ php .= sprintf (
108+ "\$ignoreErrors[] = [ \n\t%s => %s, \n\t'identifier' => %s, \n\t'count' => %s, \n\t'path' => __DIR__ . %s, \n]; \n" ,
109+ var_export ($ messageKey , true ),
110+ var_export (Helpers::escape ($ message ), true ),
111+ var_export (Helpers::escape ($ identifier ), true ),
112+ var_export ($ identifierCount , true ),
113+ var_export (Helpers::escape ($ file ), true ),
114+ );
115+ }
116+ }
117+ } else {
118+ if ($ origin !== null ) {
119+ $ php .= sprintf (
120+ "\$ignoreErrors[] = [ \n\t%s => %s, \n\t'count' => %s, \n\t'path' => __DIR__ . %s, \n\t'origin' => __DIR__ . %s, \n]; \n" ,
121+ var_export ($ messageKey , true ),
122+ var_export (Helpers::escape ($ message ), true ),
123+ var_export ($ totalCount , true ),
124+ var_export (Helpers::escape ($ file ), true ),
125+ var_export (Helpers::escape ($ origin ), true ),
126+ );
127+ } else {
89128 $ php .= sprintf (
90- "\$ignoreErrors[] = [ \n\t%s => %s, \n\t'identifier' => %s, \n\t ' count' => %s, \n\t'path' => __DIR__ . %s, \n]; \n" ,
129+ "\$ignoreErrors[] = [ \n\t%s => %s, \n\t'count' => %s, \n\t'path' => __DIR__ . %s, \n]; \n" ,
91130 var_export ($ messageKey , true ),
92131 var_export (Helpers::escape ($ message ), true ),
93- var_export (Helpers::escape ($ identifier ), true ),
94- var_export ($ identifierCount , true ),
132+ var_export ($ totalCount , true ),
95133 var_export (Helpers::escape ($ file ), true ),
96134 );
97135 }
98- } else {
99- $ php .= sprintf (
100- "\$ignoreErrors[] = [ \n\t%s => %s, \n\t'count' => %s, \n\t'path' => __DIR__ . %s, \n]; \n" ,
101- var_export ($ messageKey , true ),
102- var_export (Helpers::escape ($ message ), true ),
103- var_export ($ totalCount , true ),
104- var_export (Helpers::escape ($ file ), true ),
105- );
106136 }
107137 }
108138 }
0 commit comments