1515namespace  PhpCsFixer \Console \Report \FixReport ;
1616
1717use  PhpCsFixer \Console \Application ;
18+ use  PhpCsFixer \Documentation \DocumentationLocator ;
19+ use  PhpCsFixer \Fixer \FixerInterface ;
20+ use  PhpCsFixer \FixerFactory ;
1821use  SebastianBergmann \Diff \Chunk ;
1922use  SebastianBergmann \Diff \Diff ;
2023use  SebastianBergmann \Diff \Line ;
2528 * Generates a report according to gitlabs subset of codeclimate json files. 
2629 * 
2730 * @author Hans-Christian Otto <c.otto@suora.com> 
31+  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com> 
2832 * 
2933 * @see https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types 
3034 * 
3741final  class  GitlabReporter implements  ReporterInterface
3842{
3943    private  Parser $ diffParser
44+     private  DocumentationLocator $ documentationLocator
45+     private  FixerFactory $ fixerFactory
46+ 
47+     /** 
48+      * @var array<string, FixerInterface> 
49+      */ 
50+     private  array  $ fixers
4051
4152    public  function  __construct ()
4253    {
4354        $ this diffParser  = new  Parser ();
55+         $ this documentationLocator  = new  DocumentationLocator ();
56+ 
57+         $ this fixerFactory  = new  FixerFactory ();
58+         $ this fixerFactory ->registerBuiltInFixers ();
59+ 
60+         $ this fixers  = $ this createFixers ();
4461    }
4562
4663    public  function  getFormat (): string 
@@ -58,9 +75,23 @@ public function generate(ReportSummary $reportSummary): string
5875        $ report
5976        foreach  ($ reportSummarygetChanged () as  $ fileName$ change
6077            foreach  ($ change'appliedFixers ' ] as  $ fixerName
78+                 $ fixer$ this fixers [$ fixerNamenull ;
79+ 
6180                $ report
6281                    'check_name '  => 'PHP-CS-Fixer. ' .$ fixerName
6382                    'description '  => 'PHP-CS-Fixer. ' .$ fixerName' by  ' .$ about
83+                     'content '  => [
84+                         'body '  => \sprintf (
85+                             "%s \n%s " ,
86+                             $ about
87+                             null  !== $ fixer
88+                                 ? \sprintf (
89+                                     'Check [docs](https://cs.symfony.com/doc/rules/%s.html) for more information. ' ,
90+                                     substr ($ this documentationLocator ->getFixerDocumentationFileRelativePath ($ fixer0 , -4 ) // -4 to drop `.rst` 
91+                                 )
92+                                 : 'Check performed with a custom rule. ' 
93+                         ),
94+                     ],
6495                    'categories '  => ['Style ' ],
6596                    'fingerprint '  => md5 ($ fileName$ fixerName
6697                    'severity '  => 'minor ' ,
@@ -122,4 +153,20 @@ private static function getBeginEndForDiffChunk(Chunk $chunk): array
122153            'end '  => $ start$ startRange
123154        ];
124155    }
156+ 
157+     /** 
158+      * @return array<string, FixerInterface> 
159+      */ 
160+     private  function  createFixers (): array 
161+     {
162+         $ fixers
163+ 
164+         foreach  ($ this fixerFactory ->getFixers () as  $ fixer
165+             $ fixers$ fixergetName ()] = $ fixer
166+         }
167+ 
168+         ksort ($ fixers
169+ 
170+         return  $ fixers
171+     }
125172}
0 commit comments