├── .gitignore ├── LICENSE ├── M6Web_Symfony2 └── ruleset.xml ├── README.md ├── Symfony2 ├── Sniffs │ ├── Arrays │ │ └── MultiLineArrayCommaSniff.php │ ├── Classes │ │ ├── MultipleClassesOneFileSniff.php │ │ └── PropertyDeclarationSniff.php │ ├── Commenting │ │ ├── ClassCommentSniff.php │ │ └── FunctionCommentSniff.php │ ├── Formatting │ │ └── BlankLineBeforeReturnSniff.php │ ├── Functions │ │ └── ScopeOrderSniff.php │ ├── NamingConventions │ │ └── ValidClassNameSniff.php │ ├── Objects │ │ └── ObjectInstantiationSniff.php │ ├── Scope │ │ └── MethodScopeSniff.php │ └── WhiteSpace │ │ ├── BinaryOperatorSpacingSniff.php │ │ ├── CommaSpacingSniff.php │ │ └── DiscourageFitzinatorSniff.php ├── Tests │ ├── Arrays │ │ ├── MultiLineArrayCommaUnitTest.inc │ │ └── MultiLineArrayCommaUnitTest.php │ ├── Formatting │ │ ├── BlankLineBeforeReturnUnitTest.inc │ │ └── BlankLineBeforeReturnUnitTest.php │ └── Objects │ │ ├── ObjectInstantiationUnitTest.inc │ │ └── ObjectInstantiationUnitTest.php └── ruleset.xml └── composer.json /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | vendor/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 M6Web 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /M6Web_Symfony2/ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | M6Web coding standard for Symfony2 projects. 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Symfony2 PHP CodeSniffer Coding Standard 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/m6web/symfony2-coding-standard/v/stable)](https://packagist.org/packages/m6web/symfony2-coding-standard) 4 | [![Total Downloads](https://poser.pugx.org/m6web/symfony2-coding-standard/downloads)](https://packagist.org/packages/m6web/symfony2-coding-standard) 5 | 6 | A code standard to check against the [Symfony coding standards](http://symfony.com/doc/current/contributing/code/standards.html), forked from [opensky/Symfony2-coding-standard](https://github.com/opensky/Symfony2-coding-standard) to allow installation with composer. 7 | 8 | The reason of the fork is to use this PHP CodeSniffer coding standard with [M6Web/Coke](https://github.com/M6Web/Coke). More details [on our tech blog](http://tech.m6web.fr/verifier-la-coherence-du-code-d-un-projet-symfony2-avec-coke/) (in french). 9 | 10 | We also added to this project our own standard for our Symfony2 developments entitled `M6Web_Symfony2`. 11 | 12 | ## Installation 13 | 14 | 1. [Install composer](https://getcomposer.org/download/) 15 | 2. Create a composer.json file which contains: 16 | 17 | ```json 18 | { 19 | "require-dev": { 20 | "m6web/coke": "~2.1", 21 | "m6web/Symfony2-coding-standard": "~3.1" 22 | } 23 | } 24 | ``` 25 | 26 | 3. Install dev dependencies 27 | 28 | ```shell 29 | composer update --dev 30 | ``` 31 | 32 | 4. Create a `.coke` file a the root of the project who contain: 33 | 34 | ```shell 35 | standard=vendor/m6web/symfony2-coding-standard/Symfony2 36 | ``` 37 | 38 | or if you want to use our standard: 39 | 40 | ```shell 41 | standard=vendor/m6web/symfony2-coding-standard/M6Web_Symfony2 42 | ``` 43 | 44 | 5. Enjoy 45 | 46 | ```shell 47 | ./vendor/bin/coke 48 | ``` 49 | 50 | ## Credits 51 | 52 | Developped by [M6Web](http://tech.m6web.fr/), cloned from [lapistano/Symfony2-coding-standard](https://github.com/lapistano/Symfony2-coding-standard). 53 | The PHP_CodeSniffer 2.0+ Symfony2 standard is very broadly inspired from [escapestudios/Symfony2-coding-standard](https://github.com/escapestudios/Symfony2-coding-standard) 54 | 55 | ## License 56 | 57 | This project is licensed under the [MIT license](LICENSE). 58 | 59 | [![License](https://poser.pugx.org/m6web/symfony2-coding-standard/license)](https://packagist.org/packages/m6web/symfony2-coding-standard) 60 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Arrays/MultiLineArrayCommaSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | /** 16 | * Symfony2_Sniffs_WhiteSpace_MultiLineArrayCommaSniff. 17 | * 18 | * Throws warnings if the last item in a multi line array does not have a 19 | * trailing comma 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer-Symfony2 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_Arrays_MultiLineArrayCommaSniff 28 | implements PHP_CodeSniffer_Sniff 29 | { 30 | /** 31 | * A list of tokenizers this sniff supports. 32 | * 33 | * @var array 34 | */ 35 | public $supportedTokenizers = array( 36 | 'PHP', 37 | ); 38 | 39 | /** 40 | * Returns an array of tokens this test wants to listen for. 41 | * 42 | * @return array 43 | */ 44 | public function register() 45 | { 46 | return array( 47 | T_ARRAY, 48 | T_OPEN_SHORT_ARRAY, 49 | ); 50 | 51 | }//end register() 52 | 53 | /** 54 | * Processes this test, when one of its tokens is encountered. 55 | * 56 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 57 | * @param int $stackPtr The position of the current token 58 | * in the stack passed in $tokens. 59 | * 60 | * @return void 61 | */ 62 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 63 | { 64 | $tokens = $phpcsFile->getTokens(); 65 | $open = $tokens[$stackPtr]; 66 | 67 | if ($open['code'] === T_ARRAY) { 68 | $closePtr = $open['parenthesis_closer']; 69 | } else { 70 | $closePtr = $open['bracket_closer']; 71 | } 72 | 73 | if ($open['line'] <> $tokens[$closePtr]['line']) { 74 | $lastComma = $phpcsFile->findPrevious(T_COMMA, $closePtr); 75 | 76 | while ($lastComma < $closePtr -1) { 77 | $lastComma++; 78 | 79 | if ($tokens[$lastComma]['code'] !== T_WHITESPACE 80 | && $tokens[$lastComma]['code'] !== T_COMMENT 81 | ) { 82 | $phpcsFile->addError( 83 | 'Add a comma after each item in a multi-line array', 84 | $stackPtr, 85 | 'Invalid' 86 | ); 87 | break; 88 | } 89 | } 90 | } 91 | 92 | }//end process() 93 | 94 | }//end class 95 | 96 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Classes/MultipleClassesOneFileSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_Classes_MultipleClassesOneFileSniff. 18 | * 19 | * Throws errors if multiple classes are defined in a single file. 20 | * 21 | * Symfony coding standard specifies: "Define one class per file;" 22 | * 23 | * @category PHP 24 | * @package PHP_CodeSniffer-Symfony2 25 | * @author Dave Hauenstein 26 | * @license http://spdx.org/licenses/MIT MIT License 27 | * @link https://github.com/M6Web/Symfony2-coding-standard 28 | */ 29 | class Symfony2_Sniffs_Classes_MultipleClassesOneFileSniff implements PHP_CodeSniffer_Sniff 30 | { 31 | /** 32 | * The number of times the T_CLASS token is encountered in the file. 33 | * 34 | * @var int 35 | */ 36 | protected $classCount = 0; 37 | 38 | /** 39 | * The current file this class is operating on. 40 | * 41 | * @var string 42 | */ 43 | protected $currentFile; 44 | 45 | /** 46 | * A list of tokenizers this sniff supports. 47 | * 48 | * @var array 49 | */ 50 | public $supportedTokenizers = array( 51 | 'PHP', 52 | ); 53 | 54 | /** 55 | * Returns an array of tokens this test wants to listen for. 56 | * 57 | * @return array 58 | */ 59 | public function register() 60 | { 61 | return array(T_CLASS); 62 | } 63 | 64 | /** 65 | * Processes this test, when one of its tokens is encountered. 66 | * 67 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. 68 | * @param int $stackPtr The position of the current token in 69 | * the stack passed in $tokens. 70 | * 71 | * @return void 72 | */ 73 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 74 | { 75 | if ($this->currentFile !== $phpcsFile->getFilename()) { 76 | $this->classCount = 0; 77 | $this->currentFile = $phpcsFile->getFilename(); 78 | } 79 | 80 | $this->classCount++; 81 | 82 | if ($this->classCount > 1) { 83 | $phpcsFile->addError( 84 | 'Multiple classes defined in a single file', 85 | $stackPtr 86 | ); 87 | } 88 | 89 | return; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Classes/PropertyDeclarationSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_Classes_PropertyDeclarationSniff. 18 | * 19 | * Throws warnings if properties are declared after methods 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer-Symfony2 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_Classes_PropertyDeclarationSniff implements PHP_CodeSniffer_Sniff 28 | { 29 | 30 | /** 31 | * A list of tokenizers this sniff supports. 32 | * 33 | * @var array 34 | */ 35 | public $supportedTokenizers = array( 36 | 'PHP', 37 | ); 38 | 39 | /** 40 | * Returns an array of tokens this test wants to listen for. 41 | * 42 | * @return array 43 | */ 44 | public function register() 45 | { 46 | return array( 47 | T_CLASS, 48 | ); 49 | }//end register() 50 | 51 | /** 52 | * Processes this test, when one of its tokens is encountered. 53 | * 54 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 55 | * @param int $stackPtr The position of the current token 56 | * in the stack passed in $tokens. 57 | * 58 | * @return void 59 | */ 60 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 61 | { 62 | $tokens = $phpcsFile->getTokens(); 63 | $scope = $phpcsFile->findNext(T_FUNCTION, $stackPtr, $tokens[$stackPtr]['scope_closer']); 64 | 65 | $wantedTokens = array( 66 | T_PUBLIC, 67 | T_PROTECTED, 68 | T_PRIVATE 69 | ); 70 | 71 | while ($scope) { 72 | $scope = $phpcsFile->findNext($wantedTokens, $scope + 1, $tokens[$stackPtr]['scope_closer']); 73 | 74 | if ($scope && $tokens[$scope + 2]['code'] === T_VARIABLE) { 75 | $phpcsFile->addError( 76 | 'Declare class properties before methods', 77 | $scope, 78 | 'Invalid' 79 | ); 80 | } 81 | } 82 | }//end process() 83 | 84 | }//end class 85 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Commenting/ClassCommentSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Marc McIntyre 11 | * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) 12 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 13 | * @version CVS: $Id: ClassCommentSniff.php 301632 2010-07-28 01:57:56Z squiz $ 14 | * @link http://pear.php.net/package/PHP_CodeSniffer 15 | */ 16 | 17 | if (class_exists('PHP_CodeSniffer_Tokenizers_Comment', true) === false) { 18 | $error = 'Class PHP_CodeSniffer_Tokenizers_Comment not found'; 19 | throw new PHP_CodeSniffer_Exception($error); 20 | } 21 | 22 | if (class_exists('PEAR_Sniffs_Commenting_ClassCommentSniff', true) === false) { 23 | $error = 'Class PEAR_Sniffs_Commenting_ClassCommentSniff not found'; 24 | throw new PHP_CodeSniffer_Exception($error); 25 | } 26 | 27 | /** 28 | * Parses and verifies the doc comments for classes. 29 | * 30 | * Verifies that : 31 | *
    32 | *
  • A doc comment exists.
  • 33 | *
  • There is a blank newline after the short description.
  • 34 | *
  • There is a blank newline between the long and short description.
  • 35 | *
  • There is a blank newline between the long description and tags.
  • 36 | *
  • Check the order of the tags.
  • 37 | *
  • Check the indentation of each tag.
  • 38 | *
  • Check required and optional tags and the format of their content.
  • 39 | *
40 | * 41 | * @category PHP 42 | * @package PHP_CodeSniffer 43 | * @author Greg Sherwood 44 | * @author Marc McIntyre 45 | * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) 46 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 47 | * @version Release: 1.3.0RC2 48 | * @link http://pear.php.net/package/PHP_CodeSniffer 49 | */ 50 | class Symfony2_Sniffs_Commenting_ClassCommentSniff extends PEAR_Sniffs_Commenting_ClassCommentSniff 51 | { 52 | /** 53 | * Tags in correct order and related info. 54 | * 55 | * @var array 56 | */ 57 | protected $tags = array( 58 | 'category' => array( 59 | 'required' => false, 60 | 'allow_multiple' => false, 61 | 'order_text' => 'precedes @package', 62 | ), 63 | 'package' => array( 64 | 'required' => false, 65 | 'allow_multiple' => false, 66 | 'order_text' => 'follows @category', 67 | ), 68 | 'subpackage' => array( 69 | 'required' => false, 70 | 'allow_multiple' => false, 71 | 'order_text' => 'follows @package', 72 | ), 73 | 'author' => array( 74 | 'required' => false, 75 | 'allow_multiple' => true, 76 | 'order_text' => 'follows @subpackage (if used) or @package', 77 | ), 78 | 'copyright' => array( 79 | 'required' => false, 80 | 'allow_multiple' => true, 81 | 'order_text' => 'follows @author', 82 | ), 83 | 'license' => array( 84 | 'required' => false, 85 | 'allow_multiple' => false, 86 | 'order_text' => 'follows @copyright (if used) or @author', 87 | ), 88 | 'version' => array( 89 | 'required' => false, 90 | 'allow_multiple' => false, 91 | 'order_text' => 'follows @license', 92 | ), 93 | 'link' => array( 94 | 'required' => false, 95 | 'allow_multiple' => true, 96 | 'order_text' => 'follows @version', 97 | ), 98 | 'see' => array( 99 | 'required' => false, 100 | 'allow_multiple' => true, 101 | 'order_text' => 'follows @link', 102 | ), 103 | 'since' => array( 104 | 'required' => false, 105 | 'allow_multiple' => false, 106 | 'order_text' => 'follows @see (if used) or @link', 107 | ), 108 | 'deprecated' => array( 109 | 'required' => false, 110 | 'allow_multiple' => false, 111 | 'order_text' => 'follows @since (if used) or @see (if used) or @link', 112 | ), 113 | ); 114 | } 115 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Commenting/FunctionCommentSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | if (class_exists('PEAR_Sniffs_Commenting_FunctionCommentSniff', true) === false) { 16 | $error = 'Class PEAR_Sniffs_Commenting_FunctionCommentSniff not found'; 17 | throw new PHP_CodeSniffer_Exception($error); 18 | } 19 | 20 | /** 21 | * Symfony2 standard customization to PEARs FunctionCommentSniff. 22 | * 23 | * Verifies that : 24 | *
    25 | *
  • There is a @return tag if a return statement exists inside the method
  • 26 | *
27 | * 28 | * @category PHP 29 | * @package PHP_CodeSniffer 30 | * @author Felix Brandt 31 | * @license http://spdx.org/licenses/BSD-3-Clause BSD 3-clause "New" or "Revised" License 32 | * @link http://pear.php.net/package/PHP_CodeSniffer 33 | */ 34 | class Symfony2_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff 35 | { 36 | 37 | /** 38 | * Processes this test, when one of its tokens is encountered. 39 | * 40 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 41 | * @param int $stackPtr The position of the current token 42 | * in the stack passed in $tokens. 43 | * 44 | * @return void 45 | */ 46 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 47 | { 48 | if (false === $commentEnd = $phpcsFile->findPrevious(array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG), ($stackPtr - 1))) { 49 | return; 50 | } 51 | 52 | $tokens = $phpcsFile->getTokens(); 53 | $code = $tokens[$commentEnd]['code']; 54 | 55 | // a comment is not required on protected/private methods 56 | $method = $phpcsFile->getMethodProperties($stackPtr); 57 | $commentRequired = 'public' == $method['scope']; 58 | 59 | if (($code === T_COMMENT && !$commentRequired) 60 | || ($code !== T_DOC_COMMENT && !$commentRequired) 61 | ) { 62 | return; 63 | } 64 | 65 | parent::process($phpcsFile, $stackPtr); 66 | } 67 | 68 | /** 69 | * Process the return comment of this function comment. 70 | * 71 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 72 | * @param int $stackPtr The position of the current token 73 | * in the stack passed in $tokens. 74 | * @param int $commentStart The position in the stack where the comment started. 75 | * 76 | * @return void 77 | */ 78 | protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) 79 | { 80 | 81 | if ($this->isInheritDoc($phpcsFile, $stackPtr)) { 82 | return; 83 | } 84 | 85 | $tokens = $phpcsFile->getTokens(); 86 | 87 | // Only check for a return comment if a non-void return statement exists 88 | if (isset($tokens[$stackPtr]['scope_opener'])) { 89 | $start = $tokens[$stackPtr]['scope_opener']; 90 | 91 | // iterate over all return statements of this function, 92 | // run the check on the first which is not only 'return;' 93 | while ($returnToken = $phpcsFile->findNext(T_RETURN, $start, $tokens[$stackPtr]['scope_closer'])) { 94 | if ($this->isMatchingReturn($tokens, $returnToken) && !in_array('PHPCS_T_CLOSURE', $tokens[$returnToken]['conditions'])) { 95 | parent::processReturn($phpcsFile, $stackPtr, $commentStart); 96 | break; 97 | } 98 | $start = $returnToken + 1; 99 | } 100 | } 101 | 102 | } /* end processReturn() */ 103 | 104 | /** 105 | * Is the comment an inheritdoc? 106 | * 107 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 108 | * @param int $stackPtr The position of the current token 109 | * in the stack passed in $tokens. 110 | * 111 | * @return boolean True if the comment is an inheritdoc 112 | */ 113 | protected function isInheritDoc(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 114 | { 115 | $tokens = $phpcsFile->getTokens(); 116 | 117 | $start = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $stackPtr - 1); 118 | $end = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, $start); 119 | 120 | $content = $phpcsFile->getTokensAsString($start, ($end - $start)); 121 | 122 | return preg_match('#{@inheritdoc}#i', $content) === 1; 123 | } // end isInheritDoc() 124 | 125 | /** 126 | * Process the function parameter comments. 127 | * 128 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 129 | * @param int $stackPtr The position of the current token 130 | * in the stack passed in $tokens. 131 | * @param int $commentStart The position in the stack where the comment started. 132 | * 133 | * @return void 134 | */ 135 | protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) 136 | { 137 | $tokens = $phpcsFile->getTokens(); 138 | 139 | if ($this->isInheritDoc($phpcsFile, $stackPtr)) { 140 | return; 141 | } 142 | 143 | parent::processParams($phpcsFile, $stackPtr, $commentStart); 144 | } // end processParams() 145 | 146 | /** 147 | * Is the return statement matching? 148 | * 149 | * @param array $tokens Array of tokens 150 | * @param int $returnPos Stack position of the T_RETURN token to process 151 | * 152 | * @return boolean True if the return does not return anything 153 | */ 154 | protected function isMatchingReturn($tokens, $returnPos) 155 | { 156 | do { 157 | $returnPos++; 158 | } while ($tokens[$returnPos]['code'] === T_WHITESPACE); 159 | 160 | return $tokens[$returnPos]['code'] !== T_SEMICOLON; 161 | } 162 | 163 | }//end class 164 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Formatting/BlankLineBeforeReturnSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_Formatting_BlankLineBeforeReturnSniff. 18 | * 19 | * Throws errors if there's no blank line before return statements. Symfony 20 | * coding standard specifies: "Add a blank line before return statements, 21 | * unless the return is alone inside a statement-group (like an if statement);" 22 | * 23 | * @category PHP 24 | * @package PHP_CodeSniffer-Symfony2 25 | * @author Dave Hauenstein 26 | * @license http://spdx.org/licenses/MIT MIT License 27 | * @link https://github.com/M6Web/Symfony2-coding-standard 28 | */ 29 | class Symfony2_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSniffer_Sniff 30 | { 31 | /** 32 | * A list of tokenizers this sniff supports. 33 | * 34 | * @var array 35 | */ 36 | public $supportedTokenizers = array( 37 | 'PHP', 38 | 'JS', 39 | ); 40 | 41 | /** 42 | * Returns an array of tokens this test wants to listen for. 43 | * 44 | * @return array 45 | */ 46 | public function register() 47 | { 48 | return array(T_RETURN); 49 | } 50 | 51 | /** 52 | * Processes this test, when one of its tokens is encountered. 53 | * 54 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. 55 | * @param int $stackPtr The position of the current token in 56 | * the stack passed in $tokens. 57 | * 58 | * @return void 59 | */ 60 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 61 | { 62 | $tokens = $phpcsFile->getTokens(); 63 | $current = $stackPtr; 64 | $previousLine = $tokens[$stackPtr]['line'] - 1; 65 | $prevLineTokens = array(); 66 | 67 | while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) { 68 | if ($tokens[$current]['line'] == $previousLine 69 | && $tokens[$current]['type'] !== 'T_WHITESPACE' 70 | && $tokens[$current]['type'] !== 'T_COMMENT' 71 | && $tokens[$current]['type'] !== 'T_DOC_COMMENT_CLOSE_TAG' 72 | && $tokens[$current]['type'] !== 'T_DOC_COMMENT_WHITESPACE' 73 | ) { 74 | $prevLineTokens[] = $tokens[$current]['type']; 75 | } 76 | $current--; 77 | } 78 | 79 | if (isset($prevLineTokens[0]) 80 | && ($prevLineTokens[0] === 'T_OPEN_CURLY_BRACKET' 81 | || $prevLineTokens[0] === 'T_COLON') 82 | ) { 83 | return; 84 | } else if (count($prevLineTokens) > 0) { 85 | $phpcsFile->addError( 86 | 'Missing blank line before return statement', 87 | $stackPtr 88 | ); 89 | } 90 | 91 | return; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Functions/ScopeOrderSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_Functions_ScopeOrderSniff. 18 | * 19 | * Throws warnings if properties are declared after methods 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer-Symfony2 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_Functions_ScopeOrderSniff implements PHP_CodeSniffer_Sniff 28 | { 29 | 30 | /** 31 | * A list of tokenizers this sniff supports. 32 | * 33 | * @var array 34 | */ 35 | public $supportedTokenizers = array( 36 | 'PHP', 37 | ); 38 | 39 | /** 40 | * Returns an array of tokens this test wants to listen for. 41 | * 42 | * @return array 43 | */ 44 | public function register() 45 | { 46 | return array( 47 | T_CLASS, 48 | T_INTERFACE, 49 | ); 50 | }//end register() 51 | 52 | /** 53 | * Processes this test, when one of its tokens is encountered. 54 | * 55 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 56 | * @param int $stackPtr The position of the current token 57 | * in the stack passed in $tokens. 58 | * 59 | * @return void 60 | */ 61 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 62 | { 63 | $tokens = $phpcsFile->getTokens(); 64 | $function = $stackPtr; 65 | 66 | $scopes = array( 67 | 0 => T_PUBLIC, 68 | 1 => T_PROTECTED, 69 | 2 => T_PRIVATE, 70 | ); 71 | 72 | $whitelisted = array( 73 | '__construct', 74 | 'setUp', 75 | 'tearDown', 76 | ); 77 | 78 | while ($function) { 79 | $function = $phpcsFile->findNext(T_FUNCTION, $function + 1, $tokens[$stackPtr]['scope_closer']); 80 | 81 | if (isset($tokens[$function]['parenthesis_opener'])) { 82 | $scope = $phpcsFile->findPrevious($scopes, $function -1, $stackPtr); 83 | $name = $phpcsFile->findNext(T_STRING, $function + 1, $tokens[$function]['parenthesis_opener']); 84 | 85 | if ($scope && $name && !in_array($tokens[$name]['content'], $whitelisted)) { 86 | $current = array_keys($scopes, $tokens[$scope]['code']); 87 | $current = $current[0]; 88 | 89 | if (isset($previous) && $current < $previous) { 90 | $phpcsFile->addError( 91 | 'Declare public methods first, then protected ones and finally private ones', 92 | $scope, 93 | 'Invalid' 94 | ); 95 | } 96 | 97 | $previous = $current; 98 | } 99 | } 100 | } 101 | }//end process() 102 | 103 | }//end class 104 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/NamingConventions/ValidClassNameSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | /** 16 | * Symfony2_Sniffs_NamingConventions_ValidClassNameSniff. 17 | * 18 | * Throws errors if symfony's naming conventions are not met. 19 | * 20 | * @category PHP 21 | * @package PHP_CodeSniffer-Symfony2 22 | * @author Dave Hauenstein 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff 28 | { 29 | /** 30 | * A list of tokenizers this sniff supports. 31 | * 32 | * @var array 33 | */ 34 | public $supportedTokenizers = array( 35 | 'PHP', 36 | ); 37 | 38 | /** 39 | * Returns an array of tokens this test wants to listen for. 40 | * 41 | * @return array 42 | */ 43 | public function register() 44 | { 45 | return array( 46 | T_INTERFACE, 47 | T_TRAIT, 48 | T_EXTENDS, 49 | T_ABSTRACT 50 | ); 51 | } 52 | 53 | /** 54 | * Processes this test, when one of its tokens is encountered. 55 | * 56 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. 57 | * @param int $stackPtr The position of the current token in 58 | * the stack passed in $tokens. 59 | * 60 | * @return void 61 | */ 62 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 63 | { 64 | $tokens = $phpcsFile->getTokens(); 65 | $line = $tokens[$stackPtr]['line']; 66 | 67 | while ($tokens[$stackPtr]['line'] == $line) { 68 | 69 | /* 70 | * Suffix interfaces with Interface; 71 | */ 72 | if ('T_INTERFACE' == $tokens[$stackPtr]['type']) { 73 | $name = $phpcsFile->findNext(T_STRING, $stackPtr); 74 | 75 | if ($name && substr($tokens[$name]['content'], -9) != 'Interface') { 76 | $phpcsFile->addError( 77 | 'Interface name is not suffixed with "Interface"', 78 | $stackPtr, 79 | 'Invalid' 80 | ); 81 | } 82 | break; 83 | } 84 | 85 | /* 86 | * Suffix traits with Trait; 87 | */ 88 | if ('T_TRAIT' == $tokens[$stackPtr]['type']) { 89 | $name = $phpcsFile->findNext(T_STRING, $stackPtr); 90 | 91 | if ($name && substr($tokens[$name]['content'], -5) != 'Trait') { 92 | $phpcsFile->addError( 93 | 'Trait name is not suffixed with "Trait"', 94 | $stackPtr, 95 | 'Invalid' 96 | ); 97 | } 98 | break; 99 | } 100 | 101 | /* 102 | * Suffix exceptions with Exception; 103 | */ 104 | if ('T_EXTENDS' == $tokens[$stackPtr]['type']) { 105 | $extend = $phpcsFile->findNext(T_STRING, $stackPtr); 106 | 107 | if ($extend && substr($tokens[$extend]['content'], -9) == 'Exception') { 108 | $class = $phpcsFile->findPrevious(T_CLASS, $stackPtr); 109 | $name = $phpcsFile->findNext(T_STRING, $class); 110 | 111 | if ($name && substr($tokens[$name]['content'], -9) != 'Exception') { 112 | $phpcsFile->addError( 113 | 'Exception name is not suffixed with "Exception"', 114 | $stackPtr, 115 | 'Invalid' 116 | ); 117 | } 118 | } 119 | break; 120 | } 121 | 122 | /* 123 | * Prefix abstract classes with Abstract. 124 | */ 125 | if ('T_ABSTRACT' == $tokens[$stackPtr]['type']) { 126 | $name = $phpcsFile->findNext(T_STRING, $stackPtr); 127 | $function = $phpcsFile->findNext(T_FUNCTION, $stackPtr); 128 | 129 | // making sure we're not dealing with an abstract function 130 | if ($name && (is_null($function) || $name < $function) && substr($tokens[$name]['content'], 0, 8) != 'Abstract') { 131 | $phpcsFile->addError( 132 | 'Abstract class name is not prefixed with "Abstract"', 133 | $stackPtr, 134 | 'Invalid' 135 | ); 136 | } 137 | break; 138 | } 139 | 140 | $stackPtr++; 141 | } 142 | 143 | return; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Objects/ObjectInstantiationSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_Objects_ObjectInstantiationSniff. 18 | * 19 | * Throws a warning if an object isn't instantiated using parenthesis. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer-Symfony2 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_Objects_ObjectInstantiationSniff implements PHP_CodeSniffer_Sniff 28 | { 29 | /** 30 | * A list of tokenizers this sniff supports. 31 | * 32 | * @var array 33 | */ 34 | public $supportedTokenizers = array( 35 | 'PHP', 36 | ); 37 | 38 | 39 | /** 40 | * Returns an array of tokens this test wants to listen for. 41 | * 42 | * @return array 43 | */ 44 | public function register() 45 | { 46 | return array( 47 | T_NEW, 48 | ); 49 | 50 | }//end register() 51 | 52 | /** 53 | * Processes this test, when one of its tokens is encountered. 54 | * 55 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 56 | * @param int $stackPtr The position of the current token 57 | * in the stack passed in $tokens. 58 | * 59 | * @return void 60 | */ 61 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 62 | { 63 | $tokens = $phpcsFile->getTokens(); 64 | $allowed = array( 65 | T_STRING, 66 | T_NS_SEPARATOR, 67 | T_VARIABLE, 68 | ); 69 | 70 | $object = $stackPtr; 71 | $line = $tokens[$object]['line']; 72 | 73 | while ($object && $tokens[$object]['line'] === $line) { 74 | $object = $phpcsFile->findNext($allowed, $object + 1); 75 | 76 | if ($tokens[$object]['line'] === $line && !in_array($tokens[$object + 1]['code'], $allowed)) { 77 | if ($tokens[$object + 1]['code'] !== T_OPEN_PARENTHESIS) { 78 | $phpcsFile->addError( 79 | 'Use parentheses when instantiating classes', 80 | $stackPtr, 81 | 'Invalid' 82 | ); 83 | } 84 | 85 | break; 86 | } 87 | } 88 | 89 | }//end process() 90 | 91 | }//end class 92 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/Scope/MethodScopeSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Marc McIntyre 11 | * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) 12 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 13 | * @version CVS: $Id: MethodScopeSniff.php 301632 2010-07-28 01:57:56Z squiz $ 14 | * @link http://pear.php.net/package/PHP_CodeSniffer 15 | */ 16 | 17 | if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) { 18 | throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found'); 19 | } 20 | 21 | /** 22 | * Verifies that class members have scope modifiers. 23 | * 24 | * @category PHP 25 | * @package PHP_CodeSniffer 26 | * @author Greg Sherwood 27 | * @author Marc McIntyre 28 | * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) 29 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 30 | * @version Release: 1.3.0 31 | * @link http://pear.php.net/package/PHP_CodeSniffer 32 | */ 33 | class Symfony2_Sniffs_Scope_MethodScopeSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff 34 | { 35 | /** 36 | * Constructs a Symfony2_Sniffs_Scope_MethodScopeSniff. 37 | */ 38 | public function __construct() 39 | { 40 | parent::__construct(array(T_CLASS), array(T_FUNCTION)); 41 | 42 | }//end __construct() 43 | 44 | /** 45 | * Processes the function tokens within the class. 46 | * 47 | * @param PHP_CodeSniffer_File $phpcsFile The file where this token was found. 48 | * @param int $stackPtr The position where the token was found. 49 | * @param int $currScope The current scope opener token. 50 | * 51 | * @return void 52 | */ 53 | protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) 54 | { 55 | $tokens = $phpcsFile->getTokens(); 56 | 57 | $methodName = $phpcsFile->getDeclarationName($stackPtr); 58 | if ($methodName === null) { 59 | // Ignore closures. 60 | return; 61 | } 62 | 63 | $modifier = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$scopeModifiers, $stackPtr); 64 | if (($modifier === false) || ($tokens[$modifier]['line'] !== $tokens[$stackPtr]['line'])) { 65 | $error = 'No scope modifier specified for function "%s"'; 66 | $data = array($methodName); 67 | $phpcsFile->addError($error, $stackPtr, 'Missing', $data); 68 | } 69 | 70 | }//end processTokenWithinScope() 71 | }//end class 72 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/WhiteSpace/BinaryOperatorSpacingSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_WhiteSpace_BinaryOperatorSpacingSniff. 18 | * 19 | * Throws warnings if a binary operator isn't surrounded with whitespace. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer-Symfony2 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_WhiteSpace_BinaryOperatorSpacingSniff 28 | { 29 | /** 30 | * A list of tokenizers this sniff supports. 31 | * 32 | * @var array 33 | */ 34 | public $supportedTokenizers = array( 35 | 'PHP', 36 | ); 37 | 38 | /** 39 | * Returns an array of tokens this test wants to listen for. 40 | * 41 | * @return array 42 | */ 43 | public function register() 44 | { 45 | return PHP_CodeSniffer_Tokens::$comparisonTokens; 46 | 47 | }//end register() 48 | 49 | /** 50 | * Processes this test, when one of its tokens is encountered. 51 | * 52 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 53 | * @param int $stackPtr The position of the current token 54 | * in the stack passed in $tokens. 55 | * 56 | * @return void 57 | */ 58 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 59 | { 60 | $tokens = $phpcsFile->getTokens(); 61 | 62 | if ($tokens[$stackPtr -1]['code'] !== T_WHITESPACE || $tokens[$stackPtr +1]['code'] !== T_WHITESPACE) { 63 | $phpcsFile->addError( 64 | 'Add a single space around binary operators', 65 | $stackPtr, 66 | 'Invalid' 67 | ); 68 | } 69 | }//end process() 70 | 71 | }//end class 72 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/WhiteSpace/CommaSpacingSniff.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://spdx.org/licenses/MIT MIT License 12 | * @version GIT: master 13 | * @link https://github.com/M6Web/Symfony2-coding-standard 14 | */ 15 | 16 | /** 17 | * Symfony2_Sniffs_WhiteSpace_CommaSpacingSniff. 18 | * 19 | * Throws warnings if comma isn't followed by a whitespace. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer-Symfony2 23 | * @author wicliff wolda 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Sniffs_WhiteSpace_CommaSpacingSniff implements PHP_CodeSniffer_Sniff 28 | { 29 | /** 30 | * A list of tokenizers this sniff supports. 31 | * 32 | * @var array 33 | */ 34 | public $supportedTokenizers = array( 35 | 'PHP', 36 | ); 37 | 38 | 39 | /** 40 | * Returns an array of tokens this test wants to listen for. 41 | * 42 | * @return array 43 | */ 44 | public function register() 45 | { 46 | return array( 47 | T_COMMA, 48 | ); 49 | 50 | }//end register() 51 | 52 | /** 53 | * Processes this test, when one of its tokens is encountered. 54 | * 55 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 56 | * @param int $stackPtr The position of the current token 57 | * in the stack passed in $tokens. 58 | * 59 | * @return void 60 | */ 61 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 62 | { 63 | $tokens = $phpcsFile->getTokens(); 64 | $line = $tokens[$stackPtr]['line']; 65 | 66 | if ($tokens[$stackPtr + 1]['line'] === $line && $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE) { 67 | $phpcsFile->addError( 68 | 'Add a single space after each comma delimiter', 69 | $stackPtr, 70 | 'Invalid' 71 | ); 72 | } 73 | 74 | }//end process() 75 | 76 | }//end class 77 | 78 | -------------------------------------------------------------------------------- /Symfony2/Sniffs/WhiteSpace/DiscourageFitzinatorSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | /** 16 | * Symfony2_Sniffs_WhiteSpace_DiscourageFitzinatorSniff. 17 | * 18 | * Throws warnings if a file contains trailing whitespace. 19 | * 20 | * @category PHP 21 | * @package PHP_CodeSniffer-Symfony2 22 | * @author Justin Hileman 23 | * @license http://spdx.org/licenses/MIT MIT License 24 | * @link https://github.com/M6Web/Symfony2-coding-standard 25 | */ 26 | class Symfony2_Sniffs_WhiteSpace_DiscourageFitzinatorSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | 29 | /** 30 | * A list of tokenizers this sniff supports. 31 | * 32 | * @var array 33 | */ 34 | public $supportedTokenizers = array( 35 | 'PHP', 36 | 'JS', 37 | 'CSS', 38 | ); 39 | 40 | 41 | /** 42 | * Returns an array of tokens this test wants to listen for. 43 | * 44 | * @return array 45 | */ 46 | public function register() 47 | { 48 | return array(T_WHITESPACE); 49 | 50 | } 51 | 52 | 53 | /** 54 | * Processes this test, when one of its tokens is encountered. 55 | * 56 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. 57 | * @param int $stackPtr The position of the current token in 58 | * the stack passed in $tokens. 59 | * 60 | * @return void 61 | */ 62 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 63 | { 64 | $tokens = $phpcsFile->getTokens(); 65 | 66 | // Make sure this is trailing whitespace. 67 | $line = $tokens[$stackPtr]['line']; 68 | if (($stackPtr < count($tokens) - 1) && $tokens[($stackPtr + 1)]['line'] === $line) { 69 | return; 70 | } 71 | 72 | if (strpos($tokens[$stackPtr]['content'], "\n") > 0 || strpos($tokens[$stackPtr]['content'], "\r") > 0) { 73 | $warning = 'Please trim any trailing whitespace'; 74 | $phpcsFile->addWarning($warning, $stackPtr); 75 | } 76 | 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Symfony2/Tests/Arrays/MultiLineArrayCommaUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | /** 16 | * Unit test class for the MultiLineArrayComma sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Craige leeder 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | class Symfony2_Tests_Arrays_MultiLineArrayCommaUnitTest extends AbstractSniffUnitTest 28 | { 29 | /** 30 | * Returns the lines where errors should occur. 31 | * 32 | * The key of the array should represent the line number and the value 33 | * should represent the number of errors that should occur on that line. 34 | * 35 | * @return array 36 | */ 37 | public function getErrorList() 38 | { 39 | return array( 40 | 11 => 1, 41 | 24 => 1, 42 | 37 => 1, 43 | 47 => 1, 44 | 60 => 1, 45 | 70 => 1, 46 | ); 47 | } 48 | 49 | /** 50 | * Returns the lines where warnings should occur. 51 | * 52 | * The key of the array should represent the line number and the value 53 | * should represent the number of errors that should occur on that line. 54 | * 55 | * @return array(int => int) 56 | */ 57 | public function getWarningList() 58 | { 59 | return array(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Symfony2/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | /** 16 | * Unit test class for the BlankLineBeforeReturn sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Tom Klingenberg 24 | * @copyright 2012 Tom Klingenberg, some rights reserved. 25 | * @license http://spdx.org/licenses/MIT MIT License 26 | * @link https://github.com/M6Web/Symfony2-coding-standard 27 | */ 28 | class Symfony2_Tests_Formatting_BlankLineBeforeReturnUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 37 => 1 42 | ); 43 | } 44 | 45 | /** 46 | * Returns the lines where warnings should occur. 47 | * 48 | * The key of the array should represent the line number and the value 49 | * should represent the number of errors that should occur on that line. 50 | * 51 | * @return array(int => int) 52 | */ 53 | public function getWarningList() 54 | { 55 | return array(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Symfony2/Tests/Objects/ObjectInstantiationUnitTest.inc: -------------------------------------------------------------------------------- 1 | foo); 15 | new Foo\Bar(); 16 | new Foo\Bar(true); 17 | new Foo\Bar($this->foo); 18 | new \Foo\Bar(); 19 | new \Foo\Bar(true); 20 | new \Foo\Bar($this->foo); 21 | new $foo(); 22 | new $foo(true); 23 | new $foo($this->foo); 24 | -------------------------------------------------------------------------------- /Symfony2/Tests/Objects/ObjectInstantiationUnitTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://spdx.org/licenses/MIT MIT License 11 | * @version GIT: master 12 | * @link https://github.com/M6Web/Symfony2-coding-standard 13 | */ 14 | 15 | /** 16 | * Unit test class for the ObjectInstantiation sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Roman Weich 24 | * @license http://spdx.org/licenses/MIT MIT License 25 | * @link https://github.com/M6Web/Symfony2-coding-standard 26 | */ 27 | 28 | class Symfony2_Tests_Objects_ObjectInstantiationUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 4 => 1, 42 | 5 => 1, 43 | 6 => 1, 44 | 7 => 1, 45 | 8 => 1, 46 | ); 47 | } 48 | 49 | /** 50 | * Returns the lines where warnings should occur. 51 | * 52 | * The key of the array should represent the line number and the value 53 | * should represent the number of errors that should occur on that line. 54 | * 55 | * @return array(int => int) 56 | */ 57 | public function getWarningList() 58 | { 59 | return array(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Symfony2/ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Symfony2 coding standard. 4 | 5 | 6 | */Resources/* 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 0 69 | 70 | 71 | 72 | 73 | 0 74 | 75 | 76 | 77 | 78 | 0 79 | 80 | 81 | 0 82 | 83 | 84 | 0 85 | 86 | 87 | 88 | 0 89 | 90 | 91 | 92 | 0 93 | 94 | 95 | 96 | There should always be a description, followed by a blank line, before the tags of a class comment. 97 | 98 | 99 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "m6web/symfony2-coding-standard", 3 | "description": "Symfony2 PHP CodeSniffer Coding Standard", 4 | "keywords": ["phpcs", "CodeSniffer", "Symfony2", "Standard", "m6web"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Mikael Randy", 9 | "role": "maintainer" 10 | } 11 | ], 12 | "support" : { 13 | "source": "https://github.com/M6Web/Symfony2-coding-standard", 14 | "issues": "https://github.com/M6Web/Symfony2-coding-standard/issues" 15 | }, 16 | "require": { 17 | "squizlabs/php_codesniffer": "~2.0" 18 | }, 19 | "suggest": { 20 | "m6web/coke": "PHP CodeSniffer configurator" 21 | } 22 | } 23 | --------------------------------------------------------------------------------