Skip to content

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

Merged
merged 5 commits into from
Sep 13, 2021

Conversation

eliseacornejo
Copy link
Contributor

No description provided.

Copy link
Contributor

@svera svera left a 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?

loginesta
loginesta previously approved these changes Sep 9, 2021
@eliseacornejo
Copy link
Contributor Author

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) {
Copy link
Contributor

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()}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@sivaschenko sivaschenko left a 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.

Comment on lines 33 to 49
$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
);
}
}
Copy link
Member

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)

Suggested change
$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
);

Copy link
Contributor Author

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!

@eliseacornejo eliseacornejo marked this pull request as ready for review September 13, 2021 07:32
@eliseacornejo
Copy link
Contributor Author

@magento import pr to magento-commerce/magento-coding-standard

@magento-engcom-team
Copy link
Contributor

@eliseacornejo the pull request successfully imported.

@obukhow
Copy link

obukhow commented Sep 21, 2021

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.

@fredden
Copy link
Member

fredden commented Sep 25, 2021

@obukhow this is being discussed in #275.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants