PK s?V^@ @ CONTRIBUTING.mdnu W+A Contributing
============
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. [Add tests for your changes](https://github.com/escapestudios/Symfony2-coding-standard/blob/master/TESTING.md)
4. Push your changes to your feature branch (`git push origin my-new-feature`)
5. Create a new Pull Request (PR)
## Testing
Contributions will only be accepted if they are fully tested as specified in [TESTING.md](https://github.com/escapestudios/Symfony2-coding-standard/blob/master/TESTING.md).
PK s?VCUo o .travis.ymlnu W+A language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
- hhvm-nightly
matrix:
allow_failures:
- php: hhvm
- php: hhvm-nightly
before_script:
- export PHPCS_GITHUB_SRC=squizlabs/PHP_CodeSniffer
- export PHPCS_DIR=/tmp/phpcs
- export PHPCS_BRANCH=master
- mkdir -p $PHPCS_DIR && git clone --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git -b $PHPCS_BRANCH $PHPCS_DIR
- $PHPCS_DIR/scripts/phpcs --config-set installed_paths $(pwd)
script:
- ant travis
branches:
except:
- jenkins
notifications:
email:
- dev@escapestudios.com
PK s?VE1 build.xmlnu W+A
PK s?Vzd
composer.jsonnu W+A {
"name": "escapestudios/symfony2-coding-standard",
"type": "coding-standard",
"description": "CodeSniffer ruleset for the Symfony2 coding standard",
"keywords": ["Symfony2", "coding standard", "phpcs"],
"homepage": "https://github.com/escapestudios/Symfony2-coding-standard",
"license": "MIT",
"authors": [
{
"name": "David Joos",
"email": "david.joos@escapestudios.com"
},
{
"name": "Community contributors",
"homepage": "https://github.com/escapestudios/Symfony2-coding-standard/graphs/contributors"
}
],
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"minimum-stability": "dev",
"support" : {
"source": "https://github.com/escapestudios/Symfony2-coding-standard",
"issues": "https://github.com/escapestudios/Symfony2-coding-standard/issues"
},
"require": {
"squizlabs/php_codesniffer": "~2.0"
}
}
PK s?Va ; Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Unit test class for the BlankLineBeforeReturn 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 Tom Klingenberg
* @copyright 2012 Tom Klingenberg, some rights reserved.
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Tests_Formatting_BlankLineBeforeReturnUnitTest 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.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
37 => 1
);
}
/**
* 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 errors that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
}
}
PK s?VT˥ ; Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.incnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Unit test class for the MultiLineArrayComma 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 Craige leeder
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Tests_Arrays_MultiLineArrayCommaUnitTest 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.
*
* @return array
*/
public function getErrorList()
{
return array(
11 => 1,
24 => 1
);
}
/**
* 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 errors that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
}
}
PK s?V 5 Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.incnu W+A
The Symfony2 coding standard.
*/Resources/*
0
0
0
0
0
0
There should always be a description, followed by a blank line, before the tags of a class comment.
PK s?Vߒ 3 Symfony2/Sniffs/Commenting/FunctionCommentSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
if (class_exists('PEAR_Sniffs_Commenting_FunctionCommentSniff', true) === false) {
$error = 'Class PEAR_Sniffs_Commenting_FunctionCommentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
/**
* Symfony2 standard customization to PEARs FunctionCommentSniff.
*
* Verifies that :
*
* - There is a @return tag if a return statement exists inside the method
*
*
* @category PHP
* @package PHP_CodeSniffer
* @author Felix Brandt
* @license http://spdx.org/licenses/BSD-3-Clause BSD 3-clause "New" or "Revised" License
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Symfony2_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff
{
/**
* 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)
{
if (false === $commentEnd = $phpcsFile->findPrevious(array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG), ($stackPtr - 1))) {
return;
}
$tokens = $phpcsFile->getTokens();
$code = $tokens[$commentEnd]['code'];
// a comment is not required on protected/private methods
$method = $phpcsFile->getMethodProperties($stackPtr);
$commentRequired = 'public' == $method['scope'];
if (($code === T_COMMENT && !$commentRequired)
|| ($code !== T_DOC_COMMENT && !$commentRequired)
) {
return;
}
parent::process($phpcsFile, $stackPtr);
}
/**
* Process the return comment of this function comment.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $commentStart The position in the stack where the comment started.
*
* @return void
*/
protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
{
if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
return;
}
$tokens = $phpcsFile->getTokens();
// Only check for a return comment if a non-void return statement exists
if (isset($tokens[$stackPtr]['scope_opener'])) {
$start = $tokens[$stackPtr]['scope_opener'];
// iterate over all return statements of this function,
// run the check on the first which is not only 'return;'
while ($returnToken = $phpcsFile->findNext(T_RETURN, $start, $tokens[$stackPtr]['scope_closer'])) {
if ($this->isMatchingReturn($tokens, $returnToken)) {
parent::processReturn($phpcsFile, $stackPtr, $commentStart);
break;
}
$start = $returnToken + 1;
}
}
} /* end processReturn() */
/**
* Is the comment an inheritdoc?
*
* @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 boolean True if the comment is an inheritdoc
*/
protected function isInheritDoc(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$start = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1);
$end = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, $start);
$content = $phpcsFile->getTokensAsString($start, ($end - $start));
return preg_match('#{@inheritdoc}#i', $content) === 1;
} // end isInheritDoc()
/**
* Process the function parameter comments.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $commentStart The position in the stack where the comment started.
*
* @return void
*/
protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
{
$tokens = $phpcsFile->getTokens();
if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
return;
}
parent::processParams($phpcsFile, $stackPtr, $commentStart);
} // end processParams()
/**
* Is the return statement matching?
*
* @param array $tokens Array of tokens
* @param int $returnPos Stack position of the T_RETURN token to process
*
* @return boolean True if the return does not return anything
*/
protected function isMatchingReturn($tokens, $returnPos)
{
do {
$returnPos++;
} while ($tokens[$returnPos]['code'] === T_WHITESPACE);
return $tokens[$returnPos]['code'] !== T_SEMICOLON;
}
}//end class
PK s?V= 0 Symfony2/Sniffs/Commenting/ClassCommentSniff.phpnu W+A
* @author Marc McIntyre
* @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: ClassCommentSniff.php 301632 2010-07-28 01:57:56Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
if (class_exists('PHP_CodeSniffer_Tokenizers_Comment', true) === false) {
$error = 'Class PHP_CodeSniffer_Tokenizers_Comment not found';
throw new PHP_CodeSniffer_Exception($error);
}
if (class_exists('PEAR_Sniffs_Commenting_ClassCommentSniff', true) === false) {
$error = 'Class PEAR_Sniffs_Commenting_ClassCommentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
/**
* Parses and verifies the doc comments for classes.
*
* Verifies that :
*
* - A doc comment exists.
* - There is a blank newline after the short description.
* - There is a blank newline between the long and short description.
* - There is a blank newline between the long description and tags.
* - Check the order of the tags.
* - Check the indentation of each tag.
* - Check required and optional tags and the format of their content.
*
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood
* @author Marc McIntyre
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.0RC2
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Symfony2_Sniffs_Commenting_ClassCommentSniff extends PEAR_Sniffs_Commenting_ClassCommentSniff
{
/**
* Tags in correct order and related info.
*
* @var array
*/
protected $tags = array(
'category' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'precedes @package',
),
'package' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @category',
),
'subpackage' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @package',
),
'author' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @subpackage (if used) or @package',
),
'copyright' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @author',
),
'license' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @copyright (if used) or @author',
),
'version' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @license',
),
'link' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @version',
),
'see' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @link',
),
'since' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @see (if used) or @link',
),
'deprecated' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @since (if used) or @see (if used) or @link',
),
);
}
PK s?V(h h 9 Symfony2/Sniffs/NamingConventions/ValidClassNameSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_NamingConventions_ValidClassNameSniff.
*
* Throws errors if symfony's naming conventions are not met.
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author Dave Hauenstein
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_INTERFACE,
T_TRAIT,
T_EXTENDS,
T_ABSTRACT
);
}
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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();
$line = $tokens[$stackPtr]['line'];
while ($tokens[$stackPtr]['line'] == $line) {
/*
* Suffix interfaces with Interface;
*/
if ('T_INTERFACE' == $tokens[$stackPtr]['type']) {
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
if ($name && substr($tokens[$name]['content'], -9) != 'Interface') {
$phpcsFile->addError(
'Interface name is not suffixed with "Interface"',
$stackPtr,
'Invalid'
);
}
break;
}
/*
* Suffix traits with Trait;
*/
if ('T_TRAIT' == $tokens[$stackPtr]['type']) {
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
if ($name && substr($tokens[$name]['content'], -5) != 'Trait') {
$phpcsFile->addError(
'Trait name is not suffixed with "Trait"',
$stackPtr,
'Invalid'
);
}
break;
}
/*
* Suffix exceptions with Exception;
*/
if ('T_EXTENDS' == $tokens[$stackPtr]['type']) {
$extend = $phpcsFile->findNext(T_STRING, $stackPtr);
if ($extend && substr($tokens[$extend]['content'], -9) == 'Exception') {
$class = $phpcsFile->findPrevious(T_CLASS, $stackPtr);
$name = $phpcsFile->findNext(T_STRING, $class);
if ($name && substr($tokens[$name]['content'], -9) != 'Exception') {
$phpcsFile->addError(
'Exception name is not suffixed with "Exception"',
$stackPtr,
'Invalid'
);
}
}
break;
}
/*
* Prefix abstract classes with Abstract.
*/
if ('T_ABSTRACT' == $tokens[$stackPtr]['type']) {
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
$function = $phpcsFile->findNext(T_FUNCTION, $stackPtr);
// making sure we're not dealing with an abstract function
if ($name && (is_null($function) || $name < $function) && substr($tokens[$name]['content'], 0, 8) != 'Abstract') {
$phpcsFile->addError(
'Abstract class name is not prefixed with "Abstract"',
$stackPtr,
'Invalid'
);
}
break;
}
$stackPtr++;
}
return;
}
}
PK s?V-a 0 Symfony2/Sniffs/WhiteSpace/CommaSpacingSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_CommaSpacingSniff.
*
* Throws warnings if comma isn't followed by a whitespace.
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_WhiteSpace_CommaSpacingSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_COMMA,
);
}//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();
$line = $tokens[$stackPtr]['line'];
if ($tokens[$stackPtr + 1]['line'] === $line && $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) {
$phpcsFile->addError(
'Add a single space after each comma delimiter',
$stackPtr,
'Invalid'
);
}
}//end process()
}//end class
PK s?V2x 8 Symfony2/Sniffs/WhiteSpace/DiscourageFitzinatorSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_DiscourageFitzinatorSniff.
*
* Throws warnings if a file contains trailing whitespace.
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author Justin Hileman
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_WhiteSpace_DiscourageFitzinatorSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
'CSS',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_WHITESPACE);
}
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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();
// Make sure this is trailing whitespace.
$line = $tokens[$stackPtr]['line'];
if (($stackPtr < count($tokens) - 1) && $tokens[($stackPtr + 1)]['line'] === $line) {
return;
}
if (strpos($tokens[$stackPtr]['content'], "\n") > 0 || strpos($tokens[$stackPtr]['content'], "\r") > 0) {
$warning = 'Please trim any trailing whitespace';
$phpcsFile->addWarning($warning, $stackPtr);
}
}
}
PK s?V R 9 Symfony2/Sniffs/WhiteSpace/BinaryOperatorSpacingSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_BinaryOperatorSpacingSniff.
*
* Throws warnings if a binary operator isn't surrounded with whitespace.
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_WhiteSpace_BinaryOperatorSpacingSniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$comparisonTokens;
}//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 ($tokens[$stackPtr -1]['code'] !== T_WHITESPACE || $tokens[$stackPtr +1]['code'] !== T_WHITESPACE) {
$phpcsFile->addError(
'Add a single space around binary operators',
$stackPtr,
'Invalid'
);
}
}//end process()
}//end class
PK s?Vb- 9 Symfony2/Sniffs/Formatting/BlankLineBeforeReturnSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Formatting_BlankLineBeforeReturnSniff.
*
* Throws errors if there's no blank line before return statements. Symfony
* coding standard specifies: "Add a blank line before return statements,
* unless the return is alone inside a statement-group (like an if statement);"
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author Dave Hauenstein
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_RETURN);
}
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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();
$current = $stackPtr;
$previousLine = $tokens[$stackPtr]['line'] - 1;
$prevLineTokens = array();
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
if ($tokens[$current]['line'] == $previousLine
&& $tokens[$current]['type'] !== 'T_WHITESPACE'
&& $tokens[$current]['type'] !== 'T_COMMENT'
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_CLOSE_TAG'
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT_WHITESPACE'
) {
$prevLineTokens[] = $tokens[$current]['type'];
}
$current--;
}
if (isset($prevLineTokens[0])
&& ($prevLineTokens[0] === 'T_OPEN_CURLY_BRACKET'
|| $prevLineTokens[0] === 'T_COLON')
) {
return;
} else if (count($prevLineTokens) > 0) {
$phpcsFile->addError(
'Missing blank line before return statement',
$stackPtr
);
}
return;
}
}
PK s?Vǜ_ 4 Symfony2/Sniffs/Objects/ObjectInstantiationSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Objects_ObjectInstantiationSniff.
*
* Throws a warning if an object isn't instantiated using parenthesis.
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_Objects_ObjectInstantiationSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_NEW,
);
}//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();
$allowed = array(
T_STRING,
T_NS_SEPARATOR,
);
$object = $stackPtr;
$line = $tokens[$object]['line'];
while ($object && $tokens[$object]['line'] === $line) {
$object = $phpcsFile->findNext($allowed, $object + 1);
if ($tokens[$object]['line'] === $line && !in_array($tokens[$object + 1]['code'], $allowed)) {
if ($tokens[$object + 1]['code'] !== T_OPEN_PARENTHESIS) {
$phpcsFile->addError(
'Use parentheses when instantiating classes',
$stackPtr,
'Invalid'
);
}
break;
}
}
}//end process()
}//end class
PK s?Vg'd * Symfony2/Sniffs/Scope/MethodScopeSniff.phpnu W+A
* @author Marc McIntyre
* @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: MethodScopeSniff.php 301632 2010-07-28 01:57:56Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
}
/**
* Verifies that class members have scope modifiers.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood
* @author Marc McIntyre
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.3.0
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Symfony2_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
/**
* Constructs a Symfony2_Sniffs_Scope_MethodScopeSniff.
*/
public function __construct()
{
parent::__construct(array(T_CLASS), array(T_FUNCTION));
}//end __construct()
/**
* Processes the function tokens within the class.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
* @param int $currScope The current scope opener token.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$tokens = $phpcsFile->getTokens();
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === null) {
// Ignore closures.
return;
}
$modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr);
if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) {
$error = 'No scope modifier specified for function "%s"';
$data = array($methodName);
$phpcsFile->addError($error, $stackPtr, 'Missing', $data);
}
}//end processTokenWithinScope()
}//end class
PK s?V\3 4 Symfony2/Sniffs/Classes/PropertyDeclarationSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Classes_PropertyDeclarationSniff.
*
* Throws warnings if properties are declared after methods
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_Classes_PropertyDeclarationSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
);
}//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();
$scope = $phpcsFile->findNext(T_FUNCTION, $stackPtr, $tokens[$stackPtr]['scope_closer']);
$wantedTokens = array(
T_PUBLIC,
T_PROTECTED,
T_PRIVATE
);
while ($scope) {
$scope = $phpcsFile->findNext($wantedTokens, $scope + 1, $tokens[$stackPtr]['scope_closer']);
if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE) {
$phpcsFile->addError(
'Declare class properties before methods',
$scope,
'Invalid'
);
}
}
}//end process()
}//end class
PK s?V4\U U 7 Symfony2/Sniffs/Classes/MultipleClassesOneFileSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Classes_MultipleClassesOneFileSniff.
*
* Throws errors if multiple classes are defined in a single file.
*
* Symfony coding standard specifies: "Define one class per file;"
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author Dave Hauenstein
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_Classes_MultipleClassesOneFileSniff implements PHP_CodeSniffer_Sniff
{
/**
* The number of times the T_CLASS token is encountered in the file.
*
* @var int
*/
protected $classCount = 0;
/**
* The current file this class is operating on.
*
* @var string
*/
protected $currentFile;
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_CLASS);
}
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @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)
{
if ($this->currentFile !== $phpcsFile->getFilename()) {
$this->classCount = 0;
$this->currentFile = $phpcsFile->getFilename();
}
$this->classCount++;
if ($this->classCount > 1) {
$phpcsFile->addError(
'Multiple classes defined in a single file',
$stackPtr
);
}
return;
}
}
PK s?V1d - Symfony2/Sniffs/Functions/ScopeOrderSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Functions_ScopeOrderSniff.
*
* Throws warnings if properties are declared after methods
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_Functions_ScopeOrderSniff implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
}//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();
$function = $stackPtr;
$scopes = array(
0 => T_PUBLIC,
1 => T_PROTECTED,
2 => T_PRIVATE,
);
$whitelisted = array(
'__construct',
'setUp',
'tearDown',
);
while ($function) {
$function = $phpcsFile->findNext(T_FUNCTION, $function + 1, $tokens[$stackPtr]['scope_closer']);
if (isset($tokens[$function]['parenthesis_opener'])) {
$scope = $phpcsFile->findPrevious($scopes, $function -1, $stackPtr);
$name = $phpcsFile->findNext(T_STRING, $function + 1, $tokens[$function]['parenthesis_opener']);
if ($scope && $name && !in_array($tokens[$name]['content'], $whitelisted)) {
$current = array_keys($scopes, $tokens[$scope]['code']);
$current = $current[0];
if (isset($previous) && $current < $previous) {
$phpcsFile->addError(
'Declare public methods first, then protected ones and finally private ones',
$scope,
'Invalid'
);
}
$previous = $current;
}
}
}
}//end process()
}//end class
PK s?VPiK+
+
3 Symfony2/Sniffs/Arrays/MultiLineArrayCommaSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @version GIT: master
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_MultiLineArrayCommaSniff.
*
* Throws warnings if the last item in a multi line array does not have a
* trailing comma
*
* @category PHP
* @package PHP_CodeSniffer-Symfony2
* @author wicliff wolda
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_Arrays_MultiLineArrayCommaSniff
implements PHP_CodeSniffer_Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
);
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_ARRAY,
T_OPEN_SHORT_ARRAY,
);
}//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();
$open = $tokens[$stackPtr];
if ($open['code'] === T_ARRAY) {
$closePtr = $open['parenthesis_closer'];
} else {
$closePtr = $open['bracket_closer'];
}
if ($open['line'] <> $tokens[$closePtr]['line']) {
$lastComma = $phpcsFile->findPrevious(T_COMMA, $closePtr);
while ($lastComma < $closePtr -1) {
$lastComma++;
if ($tokens[$lastComma]['code'] !== T_WHITESPACE) {
$phpcsFile->addError(
'Add a comma after each item in a multi-line array',
$stackPtr,
'Invalid'
);
break;
}
}
}
}//end process()
}//end class
PK s?V(tH H
.gitignorenu W+A cache.properties
phpunit.xml
composer.lock
composer.phar
vendor/
build/
PK s?VV V README.mdnu W+A [![Build Status](https://secure.travis-ci.org/escapestudios/Symfony2-coding-standard.png)](http://travis-ci.org/escapestudios/Symfony2-coding-standard)
# Symfony2 PHP CodeSniffer Coding Standard
A coding standard to check against the [Symfony coding standards](http://symfony.com/doc/current/contributing/code/standards.html), originally shamelessly copied from the -disappeared- opensky/Symfony2-coding-standard repository.
## Installation
### Composer
This standard can be installed with the [Composer](https://getcomposer.org/) dependency manager.
1. [Install Composer](https://getcomposer.org/doc/00-intro.md)
2. Install the coding standard as a dependency of your project
composer require --dev escapestudios/symfony2-coding-standard:~2.0
3. Add the coding standard to the PHP_CodeSniffer install path
vendor/bin/phpcs --config-set installed_paths vendor/escapestudios/symfony2-coding-standard
4. Check the installed coding standards for "Symfony2"
vendor/bin/phpcs -i
5. Done!
vendor/bin/phpcs /path/to/code
### Stand-alone
1. Install [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
2. Checkout this repository
git clone git://github.com/escapestudios/Symfony2-coding-standard.git
3. Add the coding standard to the PHP_CodeSniffer install path
phpcs --config-set installed_paths /path/to/Symfony2-coding-standard/Symfony2
Or copy/symlink this repository's "Symfony2"-folder inside the phpcs `Standards` directory
4. Check the installed coding standards for "Symfony2"
phpcs -i
5. Done!
phpcs /path/to/code
PK s?Vu2 build.propertiesnu W+A #composer
composer.url = http://getcomposer.org/composer.phar
composer.path = ${basedir}/composer.phar
#PHP Code Sniffer
phpcs.standard = PEAR
PK s?V0
TESTING.mdnu W+A Testing
=======
Contributions to this repository will only be accepted if all tests pass successfully:
* PHP syntax/lint checks
* Unit tests: [PHPUnit](https://phpunit.de/)
* Coding standard-checks: [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki)
PK s?V^@ @ CONTRIBUTING.mdnu W+A PK s?VCUo o .travis.ymlnu W+A PK s?VE1 ) build.xmlnu W+A PK s?Vzd
composer.jsonnu W+A PK s?Va ; Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.phpnu W+A PK s?VT˥ ; 9 Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.incnu W+A PK s?Vh\ڀ 5 Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.phpnu W+A PK s?V 5 u" Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.incnu W+A PK s?V(7
# Symfony2/ruleset.xmlnu W+A PK s?Vߒ 3 2 Symfony2/Sniffs/Commenting/FunctionCommentSniff.phpnu W+A PK s?V= 0 H Symfony2/Sniffs/Commenting/ClassCommentSniff.phpnu W+A PK s?V(h h 9 Y Symfony2/Sniffs/NamingConventions/ValidClassNameSniff.phpnu W+A PK s?V-a 0 k Symfony2/Sniffs/WhiteSpace/CommaSpacingSniff.phpnu W+A PK s?V2x 8 )t Symfony2/Sniffs/WhiteSpace/DiscourageFitzinatorSniff.phpnu W+A PK s?V R 9 } Symfony2/Sniffs/WhiteSpace/BinaryOperatorSpacingSniff.phpnu W+A PK s?Vb- 9 Symfony2/Sniffs/Formatting/BlankLineBeforeReturnSniff.phpnu W+A PK s?Vǜ_ 4 ܑ Symfony2/Sniffs/Objects/ObjectInstantiationSniff.phpnu W+A PK s?Vg'd * Symfony2/Sniffs/Scope/MethodScopeSniff.phpnu W+A PK s?V\3 4 l Symfony2/Sniffs/Classes/PropertyDeclarationSniff.phpnu W+A PK s?V4\U U 7 կ Symfony2/Sniffs/Classes/MultipleClassesOneFileSniff.phpnu W+A PK s?V1d - Symfony2/Sniffs/Functions/ScopeOrderSniff.phpnu W+A PK s?VPiK+
+
3 Symfony2/Sniffs/Arrays/MultiLineArrayCommaSniff.phpnu W+A PK s?V(tH H
G .gitignorenu W+A PK s?VV V README.mdnu W+A PK s?Vu2 X build.propertiesnu W+A PK s?V0
( TESTING.mdnu W+A PK p
p