-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathCopyrightSniff.php
58 lines (48 loc) · 1.35 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
<?php
/**
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types = 1);
namespace Magento2Framework\Sniffs\Header;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
class CopyrightSniff implements Sniff
{
use CopyrightValidation;
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
/**
* @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;
}
// @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
$content = file_get_contents($phpcsFile->getFilename());
if ($this->isCopyrightYearValid($content) === false) {
$phpcsFile->addWarningOnLine(
'Copyright is missing or Copyright content/year is not valid',
null,
self::WARNING_CODE
);
}
}
}