Skip to content

Commit

Permalink
Merge branch 'master' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jun 27, 2016
2 parents d12a619 + d21a61a commit 3669a7f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
8 changes: 5 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- PHPCBF always uses this setting to reduce memory
-- Setting $recordErrors in custom reports no longer supported

- Squiz LowercasePHPFunctionsSniff now uses the internal function list so it can ignore included global functions
-- This can happen if functions are defined by calling vendor/autoload.php
-- Thanks to Michael Butler for the patch
- Generic LineLength sniff no longer errors for comments that cannot be broken out onto a new line (request #766)
-- A typical case is a comment that contains a very long URL
-- The comment is ignored if putting the URL on a indented new comment line would be longer than the allowed length
- Settings extensions in a ruleset no longer causes PHP notices during unit testing
-- Thanks to Klaus Purer for the patch
- Fixed bug #908 : PSR2 standard is not checking that closing brace is on line following the body
- Fixed bug #945 : Incorrect indent behavior using deep-nested function and arrays
- Fixed bug #961 : Two anonymous functions passed as function/method arguments cause indentation false positive
- Fixed bug #1005 : Using global composer vendor autoload breaks PHP lowercase built-in function sniff
-- Thanks to Michael Butler for the patch
- Fixed bug #1007 : Squiz Unreachable code detection is not working properly with a closure inside a case
- Fixed bug #1023 : PSR2.Classes.ClassDeclaration fails if class extends base class and "implements" is on trailing line
- Fixed bug #1026 : Arrays in comma delimited class properties cause ScopeIndent to increase indent
Expand Down
24 changes: 24 additions & 0 deletions src/Standards/Generic/Sniffs/Files/LineLengthSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ protected function checkLineLength($phpcsFile, $tokens, $stackPtr)
$phpcsFile->recordMetric($stackPtr, 'Line length', '151 or more');
}

// If this is a long comment, check if it can be broken up onto multiple lines.
// Some comments contain unbreakable strings like URLs and so it makes sense
// to ignore the line length in these cases if the URL would be longer than the max
// line length once you indent it to the correct level.
if ($lineLength > $this->lineLimit
&& ($tokens[$stackPtr]['code'] === T_COMMENT
|| $tokens[$stackPtr]['code'] === T_DOC_COMMENT_STRING)
) {
$oldLength = strlen($tokens[$stackPtr]['content']);
$newLength = strlen(ltrim($tokens[$stackPtr]['content'], "/#\t "));
$indent = (($tokens[$stackPtr]['column'] - 1) + ($oldLength - $newLength));

$nonBreakingLength = $tokens[$stackPtr]['length'];

$space = strrpos($tokens[$stackPtr]['content'], ' ');
if ($space !== false) {
$nonBreakingLength -= ($space + 1);
}

if (($nonBreakingLength + $indent) > $this->lineLimit) {
return;
}
}

if ($this->absoluteLineLimit > 0
&& $lineLength > $this->absoluteLineLimit
) {
Expand Down
23 changes: 23 additions & 0 deletions src/Standards/Generic/Tests/Files/LineLengthUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ echo 'hi';

<?php
// This is another really long comment that is going to go well over 100 characters, with no closing php tag after it.

/**
* Does something cool, blah blah, not so long line.
*
* We're using Wilson scoring because blah blah, see:
* http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval
*/

// Go here:
// http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval

# http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval

if ($foo) {
if ($bar) {
if ($baz) {
// Next line can be broken:
// foo bar baz http://en.wikipedia.org/wiki/Binomial_proportion#blahblahblahblah
// But this one is just too long to break with this indent:
// foo bar baz http://en.wikipedia.org/wiki/Binomial_proportion#blahblahblahblahblah
}
}
}
1 change: 1 addition & 0 deletions src/Standards/Generic/Tests/Files/LineLengthUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function getWarningList()
24 => 1,
29 => 1,
37 => 1,
63 => 1,
);

}//end getWarningList()
Expand Down

0 comments on commit 3669a7f

Please sign in to comment.