cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/ControlStructures InlineControlStructureSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures InlineControlStructureUnitTest.inc InlineControlStructureUnitTest.js InlineControlStructureUnitTest.php /PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures InlineControlStructureSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz SquizCodingStandard.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures InlineControlStructureSniff.php /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/ControlStructures InlineControlStructureUnitTest.inc InlineControlStructureUnitTest.js InlineControlStructureUnitTest.php
[email protected] ("Greg Sherwood")
| Newsgroups | php.pear.cvs |
|---|---|
| Message-ID | <cvssquiz1209602972@cvsserver> |
squiz Thu May 1 00:49:32 2008 UTC
Added files:
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/ControlStructures
InlineControlStructureSniff.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures
InlineControlStructureUnitTest.inc
InlineControlStructureUnitTest.js
InlineControlStructureUnitTest.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures
InlineControlStructureSniff.php
Removed files:
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures
InlineControlStructureSniff.php
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/ControlStructures
InlineControlStructureUnitTest.inc
InlineControlStructureUnitTest.js
InlineControlStructureUnitTest.php
Modified files:
/pear/PHP_CodeSniffer package.xml
/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz
SquizCodingStandard.php
Log:
Moved Squiz InlineControlStructureSniff into Generic standard and PEAR standard now throws warnings for inline control structures.
squiz-20080501004932.txt
(text/plain, 15.8 KB)
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.262&r2=1.263&diff_format=u
Index: pear/PHP_CodeSniffer/package.xml
diff -u pear/PHP_CodeSniffer/package.xml:1.262 pear/PHP_CodeSniffer/package.xml:1.263
--- pear/PHP_CodeSniffer/package.xml:1.262 Mon Apr 28 01:02:28 2008
+++ pear/PHP_CodeSniffer/package.xml Thu May 1 00:49:31 2008
@@ -33,6 +33,8 @@
<license uri="http://matrix.squiz.net/developer/tools/php_cs/licence">BSD License</license>
<notes>
- Fixed error in PEAR ValidClassNameSniff when checking class names with double underscores
+ - Moved Squiz InlineControlStructureSniff into Generic standard
+ - PEAR standard now throws warnings for inline control structures
</notes>
<contents>
<dir name="/">
@@ -177,6 +179,11 @@
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir>
+ <dir name="ControlStructures">
+ <file baseinstalldir="PHP" name="InlineControlStructureSniff.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ </dir>
<dir name="Files">
<file baseinstalldir="PHP" name="LineEndingsSniff.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
@@ -275,6 +282,13 @@
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
</dir>
+ <dir name="ControlStructures">
+ <file baseinstalldir="PHP" name="InlineControlStructureUnitTest.inc" role="test" />
+ <file baseinstalldir="PHP" name="InlineControlStructureUnitTest.js" role="test" />
+ <file baseinstalldir="PHP" name="InlineControlStructureUnitTest.php" role="test">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
+ </dir>
<dir name="Files">
<file baseinstalldir="PHP" name="LineEndingsUnitTest.inc" role="test" />
<file baseinstalldir="PHP" name="LineEndingsUnitTest.php" role="test">
@@ -486,6 +500,9 @@
<file baseinstalldir="PHP" name="ControlSignatureSniff.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
+ <file baseinstalldir="PHP" name="InlineControlStructureSniff.php" role="php">
+ <tasks:replace from="@package_version@" to="version" type="package-info" />
+ </file>
</dir>
<dir name="Files">
<file baseinstalldir="PHP" name="LineEndingsSniff.php" role="php">
@@ -697,9 +714,6 @@
<file baseinstalldir="PHP" name="ForLoopDeclarationSniff.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
- <file baseinstalldir="PHP" name="InlineControlStructureSniff.php" role="php">
- <tasks:replace from="@package_version@" to="version" type="package-info" />
- </file>
<file baseinstalldir="PHP" name="InlineIfDeclarationSniff.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
@@ -994,11 +1008,6 @@
<file baseinstalldir="PHP" name="ForLoopDeclarationUnitTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
- <file baseinstalldir="PHP" name="InlineControlStructureUnitTest.inc" role="test" />
- <file baseinstalldir="PHP" name="InlineControlStructureUnitTest.js" role="test" />
- <file baseinstalldir="PHP" name="InlineControlStructureUnitTest.php" role="test">
- <tasks:replace from="@package_version@" to="version" type="package-info" />
- </file>
<file baseinstalldir="PHP" name="InlineIfDeclarationUnitTest.inc" role="test" />
<file baseinstalldir="PHP" name="InlineIfDeclarationUnitTest.php" role="test">
<tasks:replace from="@package_version@" to="version" type="package-info" />
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/SquizCodingStandard.php?r1=1.13&r2=1.14&diff_format=u
Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/SquizCodingStandard.php
diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/SquizCodingStandard.php:1.13 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/SquizCodingStandard.php:1.14
--- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/SquizCodingStandard.php:1.13 Mon Feb 18 00:02:13 2008
+++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/SquizCodingStandard.php Thu May 1 00:49:32 2008
@@ -10,7 +10,7 @@
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version CVS: $Id: SquizCodingStandard.php,v 1.13 2008/02/18 00:02:13 squiz Exp $
+ * @version CVS: $Id: SquizCodingStandard.php,v 1.14 2008/05/01 00:49:32 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
@@ -45,6 +45,7 @@
public function getIncludedSniffs()
{
return array(
+ 'Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php',
'Generic/Sniffs/Formatting/SpaceAfterCastSniff.php',
'Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php',
'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php',
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php?view=markup&rev=1.1
Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php
+++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php
<?php
/**
* Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineControlStructureSniff.php,v 1.1 2008/05/01 00:49:31 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* Verifies that inline control statements are not present.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_ControlStructures_InlineControlStructureSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_IF,
T_ELSE,
T_FOREACH,
T_WHILE,
T_DO,
T_SWITCH,
T_FOR,
);
}//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
// Ignore the ELSE in ELSE IF. We'll process the IF part later.
if (($tokens[$stackPtr]['code'] === T_ELSE) && ($tokens[($stackPtr + 2)]['code'] === T_IF)) {
return;
}
if ($tokens[$stackPtr]['code'] === T_WHILE) {
// This could be from a DO WHILE, which doesn't have an opening brace.
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
$brace = $tokens[$lastContent];
if (isset($brace['scope_condition']) === true) {
$condition = $tokens[$brace['scope_condition']];
if ($condition['code'] === T_DO) {
return;
}
}
}
}
// This is a control structure without an opening brace,
// so it is an inline statement.
if ($this->error === true) {
$phpcsFile->addError('Inline control structures are not allowed', $stackPtr);
} else {
$phpcsFile->addWarning('Inline control structures are discouraged', $stackPtr);
}
return;
}//end if
}//end process()
}//end class
?>
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc?view=markup&rev=1.1
Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc
+++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc
<?php
if ($something) echo 'hello';
if ($something) {
echo 'hello';
} else echo 'hi';
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
foreach ($something as $thing) echo 'hello';
for ($i; $i > 0; $i--) echo 'hello';
while ($something) echo 'hello';
do {
$i--;
} while ($something);
?>
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js?view=markup&rev=1.1
Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js
+++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js
<?php
if ($something) echo 'hello';
if ($something) {
echo 'hello';
} else echo 'hi';
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
for ($i; $i > 0; $i--) echo 'hello';
while ($something) echo 'hello';
do {
$i--;
} while ($something);
?>
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php?view=markup&rev=1.1
Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php
+++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php
<?php
/**
* Unit test class for the InlineControlStructure sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineControlStructureUnitTest.php,v 1.1 2008/05/01 00:49:31 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
/**
* Unit test class for the InlineControlStructure sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_ControlStructures_InlineControlStructureUnitTest extends AbstractSniffUnitTest
{
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
{
switch ($testFile) {
case 'InlineControlStructureUnitTest.inc':
return array(
3 => 1,
7 => 1,
11 => 1,
13 => 1,
15 => 1,
17 => 1,
);
break;
case 'InlineControlStructureUnitTest.js':
return array(
3 => 1,
7 => 1,
11 => 1,
13 => 1,
15 => 1,
);
break;
default:
return array();
break;
}//end switch
}//end getErrorList()
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
}//end getWarningList()
}//end class
?>
http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/InlineControlStructureSniff.php?view=markup&rev=1.1
Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/InlineControlStructureSniff.php
+++ pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/InlineControlStructureSniff.php
<?php
/**
* PEAR_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineControlStructureSniff.php,v 1.1 2008/05/01 00:49:32 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
if (class_exists('Generic_Sniffs_ControlStructures_InlineControlStructureSniff', true) === false) {
$error = 'Class Generic_Sniffs_ControlStructures_InlineControlStructureSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
/**
* PEAR_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* Verifies that inline control statements are not present.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @author Marc McIntyre <[email protected]>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_ControlStructures_InlineControlStructureSniff extends Generic_Sniffs_ControlStructures_InlineControlStructureSniff
{
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
}//end class
?>