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?Vt^N .travis.ymlnu W+A language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
script:
- ant travis
branches:
except:
- jenkins
notifications:
email:
- dev@escapestudios.com
PK s?VT5+ build.xmlnu W+A
PK s?V{h, ,
composer.jsonnu W+A {
"name": "escapestudios/symfony2-coding-standard",
"type": "coding-standard",
"description": "CodeSniffer ruleset for the Symfony 2+ coding standard",
"keywords": ["Symfony2", "Symfony", "coding standard", "phpcs"],
"homepage": "https://github.com/djoos/Symfony2-coding-standard",
"license": "MIT",
"authors": [
{
"name": "David Joos",
"email": "david.joos@escapestudios.com"
},
{
"name": "Community contributors",
"homepage": "https://github.com/djoos/Symfony2-coding-standard/graphs/contributors"
}
],
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"minimum-stability": "dev",
"require": {
"squizlabs/php_codesniffer": "~2.0"
}
}
PK s?Vy y 5 Symfony2/Tests/Commenting/FunctionCommentUnitTest.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Unit test class for the FunctionComment 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.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Tests_Commenting_FunctionCommentUnitTest
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(
5 => 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 warnings that should occur on that line.
*
* @return array(int => int)
*/
protected function getWarningList()
{
return array();
}
}
PK s?V|E_ _ 5 Symfony2/Tests/Commenting/FunctionCommentUnitTest.incnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @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.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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 foo);
new Foo\Bar();
new Foo\Bar(true);
new Foo\Bar($this->foo);
new \Foo\Bar();
new \Foo\Bar(true);
new \Foo\Bar($this->foo);
new $foo();
new $foo(true);
new $foo($this->foo);
new static();
new static(true);
new static($this->foo);
new self();
new self(true);
new self($this->foo);
PK s?V 6 Symfony2/Tests/Objects/ObjectInstantiationUnitTest.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Unit test class for the ObjectInstantiation 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.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Tests_Objects_ObjectInstantiationUnitTest
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(
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 1,
9 => 1,
10 => 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?VV\ 5 Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @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.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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,
37 => 1,
47 => 1,
60 => 1,
70 => 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!L L 5 Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.incnu W+A
The Symfony2 coding standard.
*/Resources/*
0
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
* @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
*
*
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT 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 inside the function
$start = $phpcsFile->findNext(
T_OPEN_CURLY_BRACKET,
$stackPtr,
$tokens[$stackPtr]['scope_closer']
);
for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) {
// Skip closures
if ($tokens[$i]['code'] === T_CLOSURE) {
$i = $tokens[$i]['scope_closer'];
continue;
}
// Found a return not in a closure statement
// Run the check on the first which is not only 'return;'
if ($tokens[$i]['code'] === T_RETURN
&& $this->isMatchingReturn($tokens, $i)
) {
parent::processReturn($phpcsFile, $stackPtr, $commentStart);
break;
}
}
}
}
/**
* 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;
}
/**
* 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);
}
/**
* 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;
}
}
PK s?V&$ $ 0 Symfony2/Sniffs/Commenting/ClassCommentSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
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.
*
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT License
* @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?VH 9 Symfony2/Sniffs/NamingConventions/ValidClassNameSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_NamingConventions_ValidClassNameSniff.
*
* Throws errors if symfony's naming conventions are not met.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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,
'InvalidInterfaceName'
);
}
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,
'InvalidTraitName'
);
}
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,
'InvalidExceptionName'
);
}
}
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,
'InvalidAbstractName'
);
}
break;
}
$stackPtr++;
}
return;
}
}
PK s?V<& & 5 Symfony2/Sniffs/WhiteSpace/AssignmentSpacingSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_AssignmentSpacingSniff.
*
* Throws warnings if an assignment operator isn't surrounded with whitespace.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_WhiteSpace_AssignmentSpacingSniff
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 PHP_CodeSniffer_Tokens::$assignmentTokens;
}
/**
* 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 assignment operators',
$stackPtr,
'Invalid'
);
}
}
}
PK s?V 0 Symfony2/Sniffs/WhiteSpace/CommaSpacingSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_CommaSpacingSniff.
*
* Throws warnings if comma isn't followed by a whitespace.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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,
);
}
/**
* 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'
);
}
}
}
PK s?VY% % 8 Symfony2/Sniffs/WhiteSpace/DiscourageFitzinatorSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_DiscourageFitzinatorSniff.
*
* Throws warnings if a file contains trailing whitespace.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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?Vq% % 9 Symfony2/Sniffs/WhiteSpace/BinaryOperatorSpacingSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_WhiteSpace_BinaryOperatorSpacingSniff.
*
* Throws warnings if a binary operator isn't surrounded with whitespace.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
class Symfony2_Sniffs_WhiteSpace_BinaryOperatorSpacingSniff
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 PHP_CodeSniffer_Tokens::$comparisonTokens;
}
/**
* 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'
);
}
}
}
PK s?V>uN N 9 Symfony2/Sniffs/Formatting/BlankLineBeforeReturnSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* 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);"
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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*ر2
2
4 Symfony2/Sniffs/Objects/ObjectInstantiationSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Objects_ObjectInstantiationSniff.
*
* Throws a warning if an object isn't instantiated using parenthesis.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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,
);
}
/**
* 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,
T_VARIABLE,
T_STATIC,
T_SELF,
);
$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;
}
}
}
}
PK s?VP * Symfony2/Sniffs/Scope/MethodScopeSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
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.
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @license http://spdx.org/licenses/MIT MIT License
* @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));
}
/**
* 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);
}
}
}
PK s?Vgiq< 4 Symfony2/Sniffs/Classes/PropertyDeclarationSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Classes_PropertyDeclarationSniff.
*
* Throws warnings if properties are declared after methods
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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,
);
}
/**
* 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();
$end = null;
if (isset($tokens[$stackPtr]['scope_closer'])) {
$end = $tokens[$stackPtr]['scope_closer'];
}
$scope = $phpcsFile->findNext(
T_FUNCTION,
$stackPtr,
$end
);
$wantedTokens = array(
T_PUBLIC,
T_PROTECTED,
T_PRIVATE
);
while ($scope) {
$scope = $phpcsFile->findNext(
$wantedTokens,
$scope + 1,
$end
);
if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE) {
$phpcsFile->addError(
'Declare class properties before methods',
$scope,
'Invalid'
);
}
}
}
}
PK s?VeT; 7 Symfony2/Sniffs/Classes/MultipleClassesOneFileSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Throws errors if multiple classes are defined in a single file.
*
* PHP version 5
*
* Symfony coding standard specifies: "Define one class per file;"
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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?VT PG
- Symfony2/Sniffs/Functions/ScopeOrderSniff.phpnu W+A
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/escapestudios/Symfony2-coding-standard
*/
/**
* Symfony2_Sniffs_Functions_ScopeOrderSniff.
*
* Throws warnings if properties are declared after methods
*
* PHP version 5
*
* @category PHP
* @package Symfony2-coding-standard
* @author Authors
* @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,
);
}
/**
* 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) {
$end = null;
if (isset($tokens[$stackPtr]['scope_closer'])) {
$end = $tokens[$stackPtr]['scope_closer'];
}
$function = $phpcsFile->findNext(
T_FUNCTION,
$function + 1,
$end
);
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];
$error = 'Declare public methods first,'
.'then protected ones and finally private ones';
if (isset($previous) && $current < $previous) {
$phpcsFile->addError(
$error,
$scope,
'Invalid'
);
}
$previous = $current;
}
}
}
}
}
PK s?VJmR
R
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,
);
}
/**
* 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
&& $tokens[$lastComma]['code'] !== T_COMMENT
) {
$phpcsFile->addError(
'Add a comma after each item in a multi-line array',
$stackPtr,
'Invalid'
);
break;
}
}
}
}
}
PK s?V(tH H
.gitignorenu W+A cache.properties
phpunit.xml
composer.lock
composer.phar
vendor/
build/
PK s?V&WE E 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/djoos/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
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?V7X build.propertiesnu W+A #composer
composer.url = http://getcomposer.org/composer.phar
composer.path = ${basedir}/composer.phar
#PHP Code Sniffer
phpcs.standard = PEAR
phpcs.dir = ${basedir}/vendor/squizlabs/php_codesniffer
phpcs.symlink.path = vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/Symfony2
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?Vt^N .travis.ymlnu W+A PK s?VT5+ build.xmlnu W+A PK s?V{h, ,
composer.jsonnu W+A PK s?Vy y 5 Symfony2/Tests/Commenting/FunctionCommentUnitTest.phpnu W+A PK s?V|E_ _ 5 Symfony2/Tests/Commenting/FunctionCommentUnitTest.incnu W+A PK s?Vmv ; Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.phpnu W+A PK s?VT˥ ; Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.incnu W+A PK s?V0, 6 ! Symfony2/Tests/Objects/ObjectInstantiationUnitTest.incnu W+A PK s?V 6 $ Symfony2/Tests/Objects/ObjectInstantiationUnitTest.phpnu W+A PK s?VV\ 5 g+ Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.phpnu W+A PK s?V!L L 5 2 Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.incnu W+A PK s?V