-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathLineLengthSniff.php
36 lines (33 loc) · 1.16 KB
/
LineLengthSniff.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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sniffs\Files;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff as FilesLineLengthSniff;
/**
* Line length sniff which ignores long lines in case they contain strings intended for translation.
*/
class LineLengthSniff extends FilesLineLengthSniff
{
/**
* Having previous line content allows to ignore long lines in case of multi-line declaration.
*
* @var string
*/
protected $previousLineContent = '';
/**
* {@inheritdoc}
*/
protected function checkLineLength($phpcsFile, $stackPtr, $lineContent)
{
$previousLineRegexp = '~__\($|\bPhrase\($~';
$currentLineRegexp = '~__\(.+\)|\bPhrase\(.+\)~';
$currentLineMatch = preg_match($currentLineRegexp, $lineContent) !== 0;
$previousLineMatch = preg_match($previousLineRegexp, $this->previousLineContent) !== 0;
$this->previousLineContent = $lineContent;
if (! $currentLineMatch && !$previousLineMatch) {
parent::checkLineLength($phpcsFile, $stackPtr, $lineContent);
}
}
}