-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathCopyrightSniff.php
61 lines (50 loc) · 1.58 KB
/
CopyrightSniff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
namespace Magento2\Sniffs\Legacy;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
class CopyrightSniff implements Sniff
{
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
/**
* @inheritdoc
*/
public function register()
{
return [T_OPEN_TAG];
}
/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
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
);
}
}