-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathEmailTemplateSniff.php
50 lines (44 loc) · 1.25 KB
/
EmailTemplateSniff.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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Legacy;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Test for obsolete email directives in view/email/*.html
*/
class EmailTemplateSniff implements Sniff
{
private const OBSOLETE_EMAIL_DIRECTIVES = [
'/\{\{htmlescape.*?\}\}/i' => 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.',
'/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.',
];
private const ERROR_CODE = 'FoundObsoleteEmailDirective';
/**
* @inheritdoc
*/
public function register(): array
{
return [
T_INLINE_HTML
];
}
/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
$content = $phpcsFile->getTokens()[$stackPtr]['content'];
foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) {
if (preg_match($directiveRegex, $content)) {
$phpcsFile->addError(
$errorMessage,
$stackPtr,
self::ERROR_CODE
);
}
}
}
}