Skip to content

Commit

Permalink
PEAR IncludingFileSniff no longer produces invalid code when removing…
Browse files Browse the repository at this point in the history
… parenthesis from require/include statements
  • Loading branch information
gsherwood committed Feb 24, 2015
1 parent ee28688 commit ea46705
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken($tokens[$nextToken]['parenthesis_closer'], '');
$phpcsFile->fixer->replaceToken($nextToken, '');
if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) {
$phpcsFile->fixer->replaceToken($nextToken, ' ');
} else {
$phpcsFile->fixer->replaceToken($nextToken, '');
}

$phpcsFile->fixer->endChangeset();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ if ($var == false) {

}

?>
require_once ('blank.inc');
include_once ('blank.inc');
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

// These are statements and should not have brackets.
require_once 'blank.inc';
require 'blank.inc';

$test = true;

// Conditionally including a class file: use include_once
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}

// Unconditionally including a class file: use require_once
require_once 'blank.inc';
require 'blank.inc';


// These are ok
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}

require_once 'blank.inc';
require 'blank.inc';

?>
<pre>
Some content goes here.
<?php
require_once 'blank.inc';
require 'blank.inc';
require_once 'blank.inc';
require 'blank.inc';
?>
</pre>
<?php

if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}

if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}

function get_some_value()
{
include_once 'blank.inc';
include 'blank.inc';

// These are ok
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}

include_once 'blank.inc';
include 'blank.inc';

?>
<pre>
Some content goes here.
<?php
include_once 'blank.inc';
include 'blank.inc';
include_once 'blank.inc';
include 'blank.inc';
?>
</pre>
<?php

if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}

if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}
}


$var = include_once 'blank.inc';
if ($var == false) {

}

require_once 'blank.inc';
require_once 'blank.inc';
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function getErrorList()
74 => 1,
85 => 1,
86 => 1,
98 => 1,
99 => 2,
);

}//end getErrorList()
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Squiz OperatorSpacingSniff no longer throws errors for code in the form ($foo || -1 === $bar)
- Fixed errors tokenizing T_ELSEIF tokens on HHVM 3.5
- Squiz ArrayDeclarationSniff is no longer tricked by comments after array values
- PEAR IncludingFileSniff no longer produces invalid code when removing parenthesis from require/include statements
- Fixed bug #453 : PSR2 standard does not allow closing tag for mixed PHP/HTML files
- Fixed bug #457 : FunctionCallSignature sniffs do not support here/nowdoc syntax and can cause syntax error when fixing
- Fixed bug #466 : PropertyLabelSpacing JS fixer issue when there is no space after colon
Expand Down Expand Up @@ -1048,6 +1049,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
</dir>
<dir name="Files">
<file baseinstalldir="PHP" name="IncludingFileUnitTest.inc" role="test" />
<file baseinstalldir="PHP" name="IncludingFileUnitTest.inc.fixed" role="test" />
<file baseinstalldir="PHP" name="IncludingFileUnitTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
Expand Down

0 comments on commit ea46705

Please sign in to comment.