@@ -30,11 +30,9 @@ protected function checkFile(string $filePath, array $sniffProperties = [], arra
3030 $ codeSniffer ->registerSniffs ([$ this ->getSniffPath ()], [], []);
3131
3232 if (count ($ codesToCheck ) > 0 ) {
33- $ classReflection = new \ReflectionClass ($ this ->getSniffClassName ());
34-
3533 $ ruleset = $ propertyReflection ->getValue ($ codeSniffer );
3634
37- foreach ($ classReflection ->getConstants () as $ constantName => $ constantValue ) {
35+ foreach ($ this -> getSniffClassReflection () ->getConstants () as $ constantName => $ constantValue ) {
3836 if (strpos ($ constantName , 'CODE_ ' ) === 0 && !in_array ($ constantValue , $ codesToCheck , true )) {
3937 $ ruleset [sprintf ('%s.%s ' , $ this ->getSniffName (), $ constantValue )]['severity ' ] = 0 ;
4038 }
@@ -157,14 +155,18 @@ protected function getSniffClassName(): string
157155
158156 protected function getSniffPath (): string
159157 {
160- $ path = $ this ->getSniffClassName ();
158+ return $ this ->getSniffClassReflection ()->getFileName ();
159+ }
161160
162- $ path = str_replace ('\\' , '/ ' , $ path );
163- $ path = str_replace ('SlevomatCodingStandard ' , __DIR__ . '/../../SlevomatCodingStandard ' , $ path );
161+ protected function getSniffClassReflection (): \ReflectionClass
162+ {
163+ static $ reflection ;
164164
165- $ path .= '.php ' ;
165+ if ($ reflection === null ) {
166+ $ reflection = new \ReflectionClass ($ this ->getSniffClassName ());
167+ }
166168
167- return realpath ( $ path ) ;
169+ return $ reflection ;
168170 }
169171
170172}
0 commit comments