Skip to content

Commit e7253eb

Browse files
committed
2 parents 1151615 + 653f7ae commit e7253eb

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,16 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
114114
protected function checkLineLength(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $lineContent)
115115
{
116116
// If the content is a CVS or SVN id in a version tag, or it is
117-
// a license tag with a name and URL, there is nothing the
118-
// developer can do to shorten the line, so don't throw errors.
119-
if (preg_match('|@version[^\$]+\$Id|', $lineContent) !== 0) {
120-
return;
121-
}
122-
123-
if (preg_match('|@license|', $lineContent) !== 0) {
117+
// a license tag with a name and URL, or it is an SVN URL, there
118+
// is nothing the developer can do to shorten the line,
119+
// so don't throw errors.
120+
$regex = '~@license|@version[^\$]+\$Id|\$(Head)?URL[:\$]~';
121+
if (preg_match($regex, $lineContent) !== 0) {
124122
return;
125123
}
126124

127125
if (PHP_CODESNIFFER_ENCODING !== 'iso-8859-1') {
128-
// Not using the detault encoding, so take a bit more care.
126+
// Not using the default encoding, so take a bit more care.
129127
$lineLength = iconv_strlen($lineContent, PHP_CODESNIFFER_ENCODING);
130128
if ($lineLength === false) {
131129
// String contained invalid characters, so revert to default.

CodeSniffer/Standards/Generic/Tests/Files/LineLengthUnitTest.inc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,25 @@ echo 'hi';
4444
<?php
4545
/**
4646
* Comments contining CVS IDs can be long, but should be ignored because
47-
* they cannot be changed by the developer. Same with license URLs.
47+
* they cannot be changed by the developer. Same with license URLs. Also
48+
* and URL/HeadURL in subversion.
4849
*
4950
* @license http://www.freebsd.org/copyright/freebsd-license.html BSD License (2 Clause)
51+
*
52+
* $URL: file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $
53+
* $HeadURL: https://svn.example.org/file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $
5054
*/
55+
56+
// $URL: file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $
57+
// $HeadURL: https://svn.example.org/file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $
58+
59+
echo '$URL: file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $';
60+
echo '$HeadURL: https://svn.example.org/file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $'
61+
5162
?>
5263

64+
* $URL: file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $
65+
* $HeadURL: https://svn.example.org/file/paths/in/subversion/are/prefixed/by/URL/or/HeadURL/and/can/be/very/long/especially/if/they/are/in/a/branch $
66+
5367
<?php
5468
// This is another really long comment that is going to go well over 100 characters, with no closing php tag after it.

0 commit comments

Comments
 (0)