This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
forked from lapistano/Symfony2-coding-standard
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mod: update Symfony2 coding standard to PHP_CodeSniffer v2 interface
- Loading branch information
Mikael Randy
committed
Jul 16, 2015
1 parent
d3dee7c
commit fe112a7
Showing
22 changed files
with
966 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* This file is part of the Symfony2-coding-standard (phpcs standard) | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer-Symfony2 | ||
* @author wicliff wolda <[email protected]> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @version GIT: master | ||
* @link https://github.com/M6Web/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 <[email protected]> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @link https://github.com/M6Web/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 | ||
&& $tokens[$lastComma]['code'] !== T_COMMENT | ||
) { | ||
$phpcsFile->addError( | ||
'Add a comma after each item in a multi-line array', | ||
$stackPtr, | ||
'Invalid' | ||
); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
}//end process() | ||
|
||
}//end class | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ | |
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer-Symfony2 | ||
* @author Symfony2-phpcs-authors <Symfony2-coding-standard@opensky.github.com> | ||
* @author Symfony2-phpcs-authors <Symfony2-coding-standard@m6web.github.com> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @version GIT: master | ||
* @link https://github.com/opensky/Symfony2-coding-standard | ||
* @link https://github.com/M6Web/Symfony2-coding-standard | ||
*/ | ||
|
||
/** | ||
|
@@ -24,7 +24,7 @@ | |
* @package PHP_CodeSniffer-Symfony2 | ||
* @author Dave Hauenstein <[email protected]> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @link https://github.com/opensky/Symfony2-coding-standard | ||
* @link https://github.com/M6Web/Symfony2-coding-standard | ||
*/ | ||
class Symfony2_Sniffs_Classes_MultipleClassesOneFileSniff implements PHP_CodeSniffer_Sniff | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Symfony2-coding-standard (phpcs standard) | ||
* | ||
* PHP version 5 | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer-Symfony2 | ||
* @author wicliff wolda <[email protected]> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @version GIT: master | ||
* @link https://github.com/M6Web/Symfony2-coding-standard | ||
*/ | ||
|
||
/** | ||
* Symfony2_Sniffs_Classes_PropertyDeclarationSniff. | ||
* | ||
* Throws warnings if properties are declared after methods | ||
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer-Symfony2 | ||
* @author wicliff wolda <[email protected]> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @link https://github.com/M6Web/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ | |
* | ||
* @category PHP | ||
* @package PHP_CodeSniffer-Symfony2 | ||
* @author Symfony2-phpcs-authors <Symfony2-coding-standard@opensky.github.com> | ||
* @author Symfony2-phpcs-authors <Symfony2-coding-standard@m6web.github.com> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @version GIT: master | ||
* @link https://github.com/opensky/Symfony2-coding-standard | ||
* @link https://github.com/M6Web/Symfony2-coding-standard | ||
*/ | ||
|
||
/** | ||
|
@@ -24,7 +24,7 @@ | |
* @package PHP_CodeSniffer-Symfony2 | ||
* @author Dave Hauenstein <[email protected]> | ||
* @license http://spdx.org/licenses/MIT MIT License | ||
* @link https://github.com/opensky/Symfony2-coding-standard | ||
* @link https://github.com/M6Web/Symfony2-coding-standard | ||
*/ | ||
class Symfony2_Sniffs_Formatting_BlankLineBeforeReturnSniff implements PHP_CodeSniffer_Sniff | ||
{ | ||
|
@@ -68,6 +68,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
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']; | ||
} | ||
|
Oops, something went wrong.