|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of Applied Object Calisthenics for Symfony 2 |
| 5 | + * |
| 6 | + * PHP version 5 |
| 7 | + * |
| 8 | + * @category PHP |
| 9 | + * @package PHP_CodeSniffer-Symfony2-ObjectCalisthenics |
| 10 | + * @license http://spdx.org/licenses/MIT MIT License |
| 11 | + * @version GIT: master |
| 12 | + * @link https://github.com/instaclick/Symfony2-coding-standard |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * Symfony2_Sniffs_ObjectCalisthenics_DumpSniff. |
| 17 | + * |
| 18 | + * Debug/dump AST |
| 19 | + * |
| 20 | + * @category PHP |
| 21 | + * @package PHP_CodeSniffer-Symfony2-ObjectCalisthenics |
| 22 | + * @author Anthon Pang <[email protected]> |
| 23 | + * @license http://spdx.org/licenses/MIT MIT License |
| 24 | + * @link https://github.com/instaclick/Symfony2-coding-standard |
| 25 | + */ |
| 26 | +class Symfony2_Sniffs_ObjectCalisthenics_DumpSniff implements PHP_CodeSniffer_Sniff |
| 27 | +{ |
| 28 | + /** |
| 29 | + * A list of tokenizers this sniff supports. |
| 30 | + * |
| 31 | + * @var array |
| 32 | + */ |
| 33 | + public $supportedTokenizers = array( |
| 34 | + 'PHP', |
| 35 | + ); |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns an array of tokens this test wants to listen for. |
| 39 | + * |
| 40 | + * @return array |
| 41 | + */ |
| 42 | + public function register() |
| 43 | + { |
| 44 | + return array(T_OPEN_TAG); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Processes this test, when one of its tokens is encountered. |
| 49 | + * |
| 50 | + * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. |
| 51 | + * @param int $stackPtr The position of the current token in |
| 52 | + * the stack passed in $tokens. |
| 53 | + */ |
| 54 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
| 55 | + { |
| 56 | + return; |
| 57 | + |
| 58 | + $parser = new PHPParser_Parser(new PHPParser_Lexer); |
| 59 | + |
| 60 | + $visitor = new Symfony2_Sniffs_ObjectCalisthenics_UseAccessorsSniff_NodeVisitor; |
| 61 | + $visitor->setPHPCodeSnifferFile($phpcsFile); |
| 62 | + |
| 63 | + $traverser = new PHPParser_NodeTraverser; |
| 64 | + $traverser->addVisitor($visitor); |
| 65 | + |
| 66 | + try { |
| 67 | + $code = file_get_contents($phpcsFile->getFilename()); |
| 68 | + $tree = $parser->parse($code); |
| 69 | +//$tree[0]->setAttribute('visited', true); |
| 70 | + var_dump($tree); |
| 71 | + } catch (PHPParser_Error $e) { |
| 72 | + } |
| 73 | + die; |
| 74 | + } |
| 75 | +} |
| 76 | +// 3 - wrap primitive types and string, if it has behavior |
| 77 | +// 4 - only one -> per line, if not getter or fluent |
| 78 | +// 5 - don't abbreviate |
| 79 | +// 7 - limit the number of instance variables in a class to 5 |
| 80 | +// 8 - use first class collections |
0 commit comments