Skip to content

Commit a2864d2

Browse files
committed
AC-666: Create phpcs static check for CopyrightTest
1 parent 7a6f29f commit a2864d2

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

Magento2/Sniffs/Legacy/CopyrightSniff.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,32 @@ public function register()
3030
*/
3131
public function process(File $phpcsFile, $stackPtr)
3232
{
33-
$positionOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1);
34-
35-
if ($positionOpenTag === false) {
36-
$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr);
37-
$contentFile = $phpcsFile->getTokens()[$positionComment]['content'];
38-
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile);
39-
40-
if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
41-
return;
42-
} else {
43-
$phpcsFile->addWarningOnLine(
44-
'Copyright is missing or has wrong format',
45-
$phpcsFile->getTokens()[$positionComment]['line'],
46-
self::WARNING_CODE
47-
);
48-
}
33+
if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) {
34+
return;
4935
}
36+
37+
$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr);
38+
39+
if ($positionComment === false) {
40+
$phpcsFile->addWarning(
41+
'Copyright is missing',
42+
$stackPtr,
43+
self::WARNING_CODE
44+
);
45+
return;
46+
}
47+
48+
$content = $phpcsFile->getTokens()[$positionComment]['content'];
49+
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content);
50+
51+
if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
52+
return;
53+
}
54+
55+
$phpcsFile->addWarningOnLine(
56+
'Copyright is missing or has wrong format',
57+
$phpcsFile->getTokens()[$positionComment]['line'],
58+
self::WARNING_CODE
59+
);
5060
}
5161
}

0 commit comments

Comments
 (0)