-
Notifications
You must be signed in to change notification settings - Fork 160
AC-666: Create phpcs static check for CopyrightTest for php files #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AC-666: Create phpcs static check for CopyrightTest for php files #267
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use the Adobe copyright instead?
I don't know if we should use the Adobe one, @sivaschenko do you know if we can change the copyright to the Adobe one? |
$contentFile = $phpcsFile->getTokens()[$positionComment]['content']; | ||
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); | ||
|
||
if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) === false || $adobeCopyrightFound === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working fine. It should be:
if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound ) {return;}else{addWarning()}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @eliseacornejo ! Please see my comment.
$positionOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1); | ||
|
||
if ($positionOpenTag === false) { | ||
$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); | ||
$contentFile = $phpcsFile->getTokens()[$positionComment]['content']; | ||
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); | ||
|
||
if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { | ||
return; | ||
} else { | ||
$phpcsFile->addWarningOnLine( | ||
'Copyright is missing or has wrong format', | ||
$phpcsFile->getTokens()[$positionComment]['line'], | ||
self::WARNING_CODE | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be nice to flatten the code structure for better readability. Also handling the situation when $positionComment is false (no comments found) instantly (not trying to parse it)
$positionOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1); | |
if ($positionOpenTag === false) { | |
$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); | |
$contentFile = $phpcsFile->getTokens()[$positionComment]['content']; | |
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $contentFile); | |
if (strpos($contentFile, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { | |
return; | |
} else { | |
$phpcsFile->addWarningOnLine( | |
'Copyright is missing or has wrong format', | |
$phpcsFile->getTokens()[$positionComment]['line'], | |
self::WARNING_CODE | |
); | |
} | |
} | |
if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) { | |
return; | |
} | |
$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr); | |
if ($positionComment === false) { | |
$phpcsFile->addWarning( | |
'Copyright is missing', | |
$stackPtr, | |
self::WARNING_CODE | |
); | |
return; | |
} | |
$content = $phpcsFile->getTokens()[$positionComment]['content']; | |
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content); | |
if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) { | |
return; | |
} | |
$phpcsFile->addWarningOnLine( | |
'Copyright is missing or has wrong format', | |
$phpcsFile->getTokens()[$positionComment]['line'], | |
self::WARNING_CODE | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your collaboration. Done!
@magento import pr to magento-commerce/magento-coding-standard |
@eliseacornejo the pull request successfully imported. |
Could you please modify this sniff to work only for Magento's namespace? We don't need any Adobe or Magento copyright in our code. |
No description provided.