-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathCopyrightAnotherExtensionsFilesSniff.php
52 lines (43 loc) · 1.27 KB
/
CopyrightAnotherExtensionsFilesSniff.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
<?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 CopyrightAnotherExtensionsFilesSniff 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(): array
{
return [
T_INLINE_HTML
];
}
/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
if ($stackPtr > 0) {
return;
}
$fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText);
if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
return;
}
$phpcsFile->addWarningOnLine(
'Copyright is missing or has wrong format',
null,
self::WARNING_CODE
);
}
}