Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like File often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use File, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class File |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The absolute path to the file associated with this object. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | public $path = ''; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The absolute path to the file associated with this object. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $content = ''; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The config data for the run. |
||
| 38 | * |
||
| 39 | * @var \Symplify\PHP7_CodeSniffer\Config |
||
| 40 | */ |
||
| 41 | public $config = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The ruleset used for the run. |
||
| 45 | * |
||
| 46 | * @var \Symplify\PHP7_CodeSniffer\Ruleset |
||
| 47 | */ |
||
| 48 | public $ruleset = null; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * If TRUE, the entire file is being ignored. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | public $ignored = false; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The EOL character this file uses. |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | public $eolChar = ''; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The Fixer object to control fixing errors. |
||
| 66 | * |
||
| 67 | * @var \Symplify\PHP7_CodeSniffer\Fixer |
||
| 68 | */ |
||
| 69 | public $fixer = null; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The tokenizer being used for this file. |
||
| 73 | * |
||
| 74 | * @var \Symplify\PHP7_CodeSniffer\Tokenizers\Tokenizer |
||
| 75 | */ |
||
| 76 | public $tokenizer = null; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Was the file loaded from cache? |
||
| 80 | * |
||
| 81 | * If TRUE, the file was loaded from a local cache. |
||
| 82 | * If FALSE, the file was tokenized and processed fully. |
||
| 83 | * |
||
| 84 | * @var boolean |
||
| 85 | */ |
||
| 86 | public $fromCache = false; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * The number of tokens in this file. |
||
| 90 | * |
||
| 91 | * Stored here to save calling count() everywhere. |
||
| 92 | * |
||
| 93 | * @var integer |
||
| 94 | */ |
||
| 95 | public $numTokens = 0; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * The tokens stack map. |
||
| 99 | * |
||
| 100 | * @var array |
||
| 101 | */ |
||
| 102 | protected $tokens = array(); |
||
| 103 | |||
| 104 | /** |
||
| 105 | * The errors raised from sniffs. |
||
| 106 | * |
||
| 107 | * @var array |
||
| 108 | * @see getErrors() |
||
| 109 | */ |
||
| 110 | protected $errors = array(); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * The warnings raised from sniffs. |
||
| 114 | * |
||
| 115 | * @var array |
||
| 116 | * @see getWarnings() |
||
| 117 | */ |
||
| 118 | protected $warnings = array(); |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The metrics recorded by sniffs. |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | * @see getMetrics() |
||
| 125 | */ |
||
| 126 | protected $metrics = array(); |
||
| 127 | |||
| 128 | /** |
||
| 129 | * The total number of errors raised. |
||
| 130 | * |
||
| 131 | * @var integer |
||
| 132 | */ |
||
| 133 | protected $errorCount = 0; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * The total number of warnings raised. |
||
| 137 | * |
||
| 138 | * @var integer |
||
| 139 | */ |
||
| 140 | protected $warningCount = 0; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * The total number of errors and warnings that can be fixed. |
||
| 144 | * |
||
| 145 | * @var integer |
||
| 146 | */ |
||
| 147 | protected $fixableCount = 0; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * An array of sniffs that are being ignored. |
||
| 151 | * |
||
| 152 | * @var array |
||
| 153 | */ |
||
| 154 | protected $ignoredListeners = array(); |
||
| 155 | |||
| 156 | /** |
||
| 157 | * An array of message codes that are being ignored. |
||
| 158 | * |
||
| 159 | * @var array |
||
| 160 | */ |
||
| 161 | protected $ignoredCodes = array(); |
||
| 162 | |||
| 163 | /** |
||
| 164 | * An array of sniffs listening to this file's processing. |
||
| 165 | * |
||
| 166 | * @var \Symplify\PHP7_CodeSniffer\Sniffs\Sniff[] |
||
| 167 | */ |
||
| 168 | protected $listeners = array(); |
||
| 169 | |||
| 170 | /** |
||
| 171 | * The class name of the sniff currently processing the file. |
||
| 172 | * |
||
| 173 | * @var string |
||
| 174 | */ |
||
| 175 | protected $activeListener = ''; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * An array of sniffs being processed and how long they took. |
||
| 179 | * |
||
| 180 | * @var array |
||
| 181 | */ |
||
| 182 | protected $listenerTimes = array(); |
||
| 183 | |||
| 184 | /** |
||
| 185 | * A cache of often used config settings to improve performance. |
||
| 186 | * |
||
| 187 | * Storing them here saves 10k+ calls to __get() in the Config class. |
||
| 188 | * |
||
| 189 | * @var array |
||
| 190 | */ |
||
| 191 | protected $configCache = array(); |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * Constructs a file. |
||
| 196 | * |
||
| 197 | * @param string $path The absolute path to the file to process. |
||
| 198 | * @param \Symplify\PHP7_CodeSniffer\Ruleset $ruleset The ruleset used for the run. |
||
| 199 | * @param \Symplify\PHP7_CodeSniffer\Config $config The config data for the run. |
||
| 200 | * |
||
| 201 | * @return void |
||
|
|
|||
| 202 | */ |
||
| 203 | public function __construct($path, Ruleset $ruleset, Config $config) |
||
| 227 | |||
| 228 | |||
| 229 | /** |
||
| 230 | * Set the content of the file. |
||
| 231 | * |
||
| 232 | * Setting the content also calculates the EOL char being used. |
||
| 233 | * |
||
| 234 | * @param string $content The file content. |
||
| 235 | * |
||
| 236 | * @return void |
||
| 237 | */ |
||
| 238 | function setContent($content) |
||
| 251 | |||
| 252 | |||
| 253 | /** |
||
| 254 | * Reloads the content of the file. |
||
| 255 | * |
||
| 256 | * By default, we have no idea where our content comes from, |
||
| 257 | * so we can't do anything. |
||
| 258 | * |
||
| 259 | * @return void |
||
| 260 | */ |
||
| 261 | function reloadContent() |
||
| 265 | |||
| 266 | |||
| 267 | /** |
||
| 268 | * Disables caching of this file. |
||
| 269 | * |
||
| 270 | * @return void |
||
| 271 | */ |
||
| 272 | function disableCaching() |
||
| 277 | |||
| 278 | |||
| 279 | /** |
||
| 280 | * Starts the stack traversal and tells listeners when tokens are found. |
||
| 281 | * |
||
| 282 | * @return void |
||
| 283 | */ |
||
| 284 | public function process() |
||
| 424 | |||
| 425 | |||
| 426 | /** |
||
| 427 | * Tokenizes the file and prepares it for the test run. |
||
| 428 | * |
||
| 429 | * @return void |
||
| 430 | */ |
||
| 431 | public function parse() |
||
| 488 | |||
| 489 | |||
| 490 | /** |
||
| 491 | * Returns the token stack for this file. |
||
| 492 | * |
||
| 493 | * @return array |
||
| 494 | */ |
||
| 495 | public function getTokens() |
||
| 500 | |||
| 501 | |||
| 502 | /** |
||
| 503 | * Remove vars stored in this file that are no longer required. |
||
| 504 | * |
||
| 505 | * @return void |
||
| 506 | */ |
||
| 507 | public function cleanUp() |
||
| 516 | |||
| 517 | |||
| 518 | /** |
||
| 519 | * Records an error against a specific token in the file. |
||
| 520 | * |
||
| 521 | * @param string $error The error message. |
||
| 522 | * @param int $stackPtr The stack position where the error occurred. |
||
| 523 | * @param string $code A violation code unique to the sniff message. |
||
| 524 | * @param array $data Replacements for the error message. |
||
| 525 | * @param int $severity The severity level for this error. A value of 0 |
||
| 526 | * will be converted into the default severity level. |
||
| 527 | * @param boolean $fixable Can the error be fixed by the sniff? |
||
| 528 | * |
||
| 529 | * @return boolean |
||
| 530 | */ |
||
| 531 | View Code Duplication | public function addError( |
|
| 550 | |||
| 551 | |||
| 552 | /** |
||
| 553 | * Records a warning against a specific token in the file. |
||
| 554 | * |
||
| 555 | * @param string $warning The error message. |
||
| 556 | * @param int $stackPtr The stack position where the error occurred. |
||
| 557 | * @param string $code A violation code unique to the sniff message. |
||
| 558 | * @param array $data Replacements for the warning message. |
||
| 559 | * @param int $severity The severity level for this warning. A value of 0 |
||
| 560 | * will be converted into the default severity level. |
||
| 561 | * @param boolean $fixable Can the warning be fixed by the sniff? |
||
| 562 | * |
||
| 563 | * @return boolean |
||
| 564 | */ |
||
| 565 | View Code Duplication | public function addWarning( |
|
| 584 | |||
| 585 | |||
| 586 | /** |
||
| 587 | * Records an error against a specific line in the file. |
||
| 588 | * |
||
| 589 | * @param string $error The error message. |
||
| 590 | * @param int $line The line on which the error occurred. |
||
| 591 | * @param string $code A violation code unique to the sniff message. |
||
| 592 | * @param array $data Replacements for the error message. |
||
| 593 | * @param int $severity The severity level for this error. A value of 0 |
||
| 594 | * will be converted into the default severity level. |
||
| 595 | * |
||
| 596 | * @return boolean |
||
| 597 | */ |
||
| 598 | public function addErrorOnLine( |
||
| 608 | |||
| 609 | |||
| 610 | /** |
||
| 611 | * Records a warning against a specific token in the file. |
||
| 612 | * |
||
| 613 | * @param string $warning The error message. |
||
| 614 | * @param int $line The line on which the warning occurred. |
||
| 615 | * @param string $code A violation code unique to the sniff message. |
||
| 616 | * @param array $data Replacements for the warning message. |
||
| 617 | * @param int $severity The severity level for this warning. A value of 0 will |
||
| 618 | * will be converted into the default severity level. |
||
| 619 | * |
||
| 620 | * @return boolean |
||
| 621 | */ |
||
| 622 | public function addWarningOnLine( |
||
| 632 | |||
| 633 | |||
| 634 | /** |
||
| 635 | * Records a fixable error against a specific token in the file. |
||
| 636 | * |
||
| 637 | * Returns true if the error was recorded and should be fixed. |
||
| 638 | * |
||
| 639 | * @param string $error The error message. |
||
| 640 | * @param int $stackPtr The stack position where the error occurred. |
||
| 641 | * @param string $code A violation code unique to the sniff message. |
||
| 642 | * @param array $data Replacements for the error message. |
||
| 643 | * @param int $severity The severity level for this error. A value of 0 |
||
| 644 | * will be converted into the default severity level. |
||
| 645 | * |
||
| 646 | * @return boolean |
||
| 647 | */ |
||
| 648 | View Code Duplication | public function addFixableError( |
|
| 663 | |||
| 664 | |||
| 665 | /** |
||
| 666 | * Records a fixable warning against a specific token in the file. |
||
| 667 | * |
||
| 668 | * Returns true if the warning was recorded and should be fixed. |
||
| 669 | * |
||
| 670 | * @param string $warning The error message. |
||
| 671 | * @param int $stackPtr The stack position where the error occurred. |
||
| 672 | * @param string $code A violation code unique to the sniff message. |
||
| 673 | * @param array $data Replacements for the warning message. |
||
| 674 | * @param int $severity The severity level for this warning. A value of 0 |
||
| 675 | * will be converted into the default severity level. |
||
| 676 | * |
||
| 677 | * @return boolean |
||
| 678 | */ |
||
| 679 | View Code Duplication | public function addFixableWarning( |
|
| 694 | |||
| 695 | |||
| 696 | /** |
||
| 697 | * Adds an error to the error stack. |
||
| 698 | * |
||
| 699 | * @param boolean $error Is this an error message? |
||
| 700 | * @param string $message The text of the message. |
||
| 701 | * @param int $line The line on which the message occurred. |
||
| 702 | * @param int $column The column at which the message occurred. |
||
| 703 | * @param string $code A violation code unique to the sniff message. |
||
| 704 | * @param array $data Replacements for the message. |
||
| 705 | * @param int $severity The severity level for this message. A value of 0 |
||
| 706 | * will be converted into the default severity level. |
||
| 707 | * @param boolean $fixable Can the problem be fixed by the sniff? |
||
| 708 | * |
||
| 709 | * @return boolean |
||
| 710 | */ |
||
| 711 | protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable) |
||
| 890 | |||
| 891 | |||
| 892 | /** |
||
| 893 | * Adds an warning to the warning stack. |
||
| 894 | * |
||
| 895 | * @param int $stackPtr The stack position where the metric was recorded. |
||
| 896 | * @param string $metric The name of the metric being recorded. |
||
| 897 | * @param string $value The value of the metric being recorded. |
||
| 898 | * |
||
| 899 | * @return boolean |
||
| 900 | */ |
||
| 901 | public function recordMetric($stackPtr, $metric, $value) |
||
| 916 | |||
| 917 | |||
| 918 | /** |
||
| 919 | * Returns the number of errors raised. |
||
| 920 | * |
||
| 921 | * @return int |
||
| 922 | */ |
||
| 923 | public function getErrorCount() |
||
| 928 | |||
| 929 | |||
| 930 | /** |
||
| 931 | * Returns the number of warnings raised. |
||
| 932 | * |
||
| 933 | * @return int |
||
| 934 | */ |
||
| 935 | public function getWarningCount() |
||
| 940 | |||
| 941 | |||
| 942 | /** |
||
| 943 | * Returns the number of successes recorded. |
||
| 944 | * |
||
| 945 | * @return int |
||
| 946 | */ |
||
| 947 | public function getSuccessCount() |
||
| 952 | |||
| 953 | |||
| 954 | /** |
||
| 955 | * Returns the number of fixable errors/warnings raised. |
||
| 956 | * |
||
| 957 | * @return int |
||
| 958 | */ |
||
| 959 | public function getFixableCount() |
||
| 964 | |||
| 965 | |||
| 966 | /** |
||
| 967 | * Returns the list of ignored lines. |
||
| 968 | * |
||
| 969 | * @return array |
||
| 970 | */ |
||
| 971 | public function getIgnoredLines() |
||
| 976 | |||
| 977 | |||
| 978 | /** |
||
| 979 | * Returns the errors raised from processing this file. |
||
| 980 | * |
||
| 981 | * @return array |
||
| 982 | */ |
||
| 983 | public function getErrors() |
||
| 988 | |||
| 989 | |||
| 990 | /** |
||
| 991 | * Returns the warnings raised from processing this file. |
||
| 992 | * |
||
| 993 | * @return array |
||
| 994 | */ |
||
| 995 | public function getWarnings() |
||
| 1000 | |||
| 1001 | |||
| 1002 | /** |
||
| 1003 | * Returns the metrics found while processing this file. |
||
| 1004 | * |
||
| 1005 | * @return array |
||
| 1006 | */ |
||
| 1007 | public function getMetrics() |
||
| 1012 | |||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Returns the absolute filename of this file. |
||
| 1016 | * |
||
| 1017 | * @return string |
||
| 1018 | */ |
||
| 1019 | public function getFilename() |
||
| 1024 | |||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Returns the declaration names for T_CLASS, T_INTERFACE and T_FUNCTION tokens. |
||
| 1028 | * |
||
| 1029 | * @param int $stackPtr The position of the declaration token which |
||
| 1030 | * declared the class, interface or function. |
||
| 1031 | * |
||
| 1032 | * @return string|null The name of the class, interface or function. |
||
| 1033 | * or NULL if the function is a closure. |
||
| 1034 | * @throws Symplify\PHP7_CodeSniffer_Exception If the specified token is not of type |
||
| 1035 | * T_FUNCTION, T_CLASS or T_INTERFACE. |
||
| 1036 | */ |
||
| 1037 | public function getDeclarationName($stackPtr) |
||
| 1065 | |||
| 1066 | |||
| 1067 | /** |
||
| 1068 | * Check if the token at the specified position is a anonymous function. |
||
| 1069 | * |
||
| 1070 | * @param int $stackPtr The position of the declaration token which |
||
| 1071 | * declared the class, interface or function. |
||
| 1072 | * |
||
| 1073 | * @return boolean |
||
| 1074 | * @throws Symplify\PHP7_CodeSniffer_Exception If the specified token is not of type |
||
| 1075 | * T_FUNCTION |
||
| 1076 | */ |
||
| 1077 | public function isAnonymousFunction($stackPtr) |
||
| 1110 | |||
| 1111 | |||
| 1112 | /** |
||
| 1113 | * Returns the method parameters for the specified T_FUNCTION token. |
||
| 1114 | * |
||
| 1115 | * Each parameter is in the following format: |
||
| 1116 | * |
||
| 1117 | * <code> |
||
| 1118 | * 0 => array( |
||
| 1119 | * 'name' => '$var', // The variable name. |
||
| 1120 | * 'pass_by_reference' => false, // Passed by reference. |
||
| 1121 | * 'type_hint' => string, // Type hint for array or custom type |
||
| 1122 | * ) |
||
| 1123 | * </code> |
||
| 1124 | * |
||
| 1125 | * Parameters with default values have an additional array index of |
||
| 1126 | * 'default' with the value of the default as a string. |
||
| 1127 | * |
||
| 1128 | * @param int $stackPtr The position in the stack of the T_FUNCTION token |
||
| 1129 | * to acquire the parameters for. |
||
| 1130 | * |
||
| 1131 | * @return array |
||
| 1132 | * @throws Symplify\PHP7_CodeSniffer_Exception If the specified $stackPtr is not of |
||
| 1133 | * type T_FUNCTION. |
||
| 1134 | */ |
||
| 1135 | public function getMethodParameters($stackPtr) |
||
| 1260 | |||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Returns the visibility and implementation properties of a method. |
||
| 1264 | * |
||
| 1265 | * The format of the array is: |
||
| 1266 | * <code> |
||
| 1267 | * array( |
||
| 1268 | * 'scope' => 'public', // public protected or protected |
||
| 1269 | * 'scope_specified' => true, // true is scope keyword was found. |
||
| 1270 | * 'is_abstract' => false, // true if the abstract keyword was found. |
||
| 1271 | * 'is_final' => false, // true if the final keyword was found. |
||
| 1272 | * 'is_static' => false, // true if the static keyword was found. |
||
| 1273 | * 'is_closure' => false, // true if no name is found. |
||
| 1274 | * ); |
||
| 1275 | * </code> |
||
| 1276 | * |
||
| 1277 | * @param int $stackPtr The position in the stack of the T_FUNCTION token to |
||
| 1278 | * acquire the properties for. |
||
| 1279 | * |
||
| 1280 | * @return array |
||
| 1281 | * @throws Symplify\PHP7_CodeSniffer_Exception If the specified position is not a |
||
| 1282 | * T_FUNCTION token. |
||
| 1283 | */ |
||
| 1284 | public function getMethodProperties($stackPtr) |
||
| 1349 | |||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Returns the visibility and implementation properties of the class member |
||
| 1353 | * variable found at the specified position in the stack. |
||
| 1354 | * |
||
| 1355 | * The format of the array is: |
||
| 1356 | * |
||
| 1357 | * <code> |
||
| 1358 | * array( |
||
| 1359 | * 'scope' => 'public', // public protected or protected |
||
| 1360 | * 'is_static' => false, // true if the static keyword was found. |
||
| 1361 | * ); |
||
| 1362 | * </code> |
||
| 1363 | * |
||
| 1364 | * @param int $stackPtr The position in the stack of the T_VARIABLE token to |
||
| 1365 | * acquire the properties for. |
||
| 1366 | * |
||
| 1367 | * @return array |
||
| 1368 | * @throws Symplify\PHP7_CodeSniffer_Exception If the specified position is not a |
||
| 1369 | * T_VARIABLE token, or if the position is not |
||
| 1370 | * a class member variable. |
||
| 1371 | */ |
||
| 1372 | public function getMemberProperties($stackPtr) |
||
| 1450 | |||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Returns the visibility and implementation properties of a class. |
||
| 1454 | * |
||
| 1455 | * The format of the array is: |
||
| 1456 | * <code> |
||
| 1457 | * array( |
||
| 1458 | * 'is_abstract' => false, // true if the abstract keyword was found. |
||
| 1459 | * 'is_final' => false, // true if the final keyword was found. |
||
| 1460 | * ); |
||
| 1461 | * </code> |
||
| 1462 | * |
||
| 1463 | * @param int $stackPtr The position in the stack of the T_CLASS token to |
||
| 1464 | * acquire the properties for. |
||
| 1465 | * |
||
| 1466 | * @return array |
||
| 1467 | * @throws Symplify\PHP7_CodeSniffer_Exception If the specified position is not a |
||
| 1468 | * T_CLASS token. |
||
| 1469 | */ |
||
| 1470 | public function getClassProperties($stackPtr) |
||
| 1509 | |||
| 1510 | |||
| 1511 | /** |
||
| 1512 | * Determine if the passed token is a reference operator. |
||
| 1513 | * |
||
| 1514 | * Returns true if the specified token position represents a reference. |
||
| 1515 | * Returns false if the token represents a bitwise operator. |
||
| 1516 | * |
||
| 1517 | * @param int $stackPtr The position of the T_BITWISE_AND token. |
||
| 1518 | * |
||
| 1519 | * @return boolean |
||
| 1520 | */ |
||
| 1521 | public function isReference($stackPtr) |
||
| 1604 | |||
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Returns the content of the tokens from the specified start position in |
||
| 1608 | * the token stack for the specified length. |
||
| 1609 | * |
||
| 1610 | * @param int $start The position to start from in the token stack. |
||
| 1611 | * @param int $length The length of tokens to traverse from the start pos. |
||
| 1612 | * |
||
| 1613 | * @return string The token contents. |
||
| 1614 | */ |
||
| 1615 | public function getTokensAsString($start, $length) |
||
| 1630 | |||
| 1631 | |||
| 1632 | /** |
||
| 1633 | * Returns the position of the previous specified token(s). |
||
| 1634 | * |
||
| 1635 | * If a value is specified, the previous token of the specified type(s) |
||
| 1636 | * containing the specified value will be returned. |
||
| 1637 | * |
||
| 1638 | * Returns false if no token can be found. |
||
| 1639 | * |
||
| 1640 | * @param int|array $types The type(s) of tokens to search for. |
||
| 1641 | * @param int $start The position to start searching from in the |
||
| 1642 | * token stack. |
||
| 1643 | * @param int $end The end position to fail if no token is found. |
||
| 1644 | * if not specified or null, end will default to |
||
| 1645 | * the start of the token stack. |
||
| 1646 | * @param bool $exclude If true, find the previous token that is NOT of |
||
| 1647 | * the types specified in $types. |
||
| 1648 | * @param string $value The value that the token(s) must be equal to. |
||
| 1649 | * If value is omitted, tokens with any value will |
||
| 1650 | * be returned. |
||
| 1651 | * @param bool $local If true, tokens outside the current statement |
||
| 1652 | * will not be checked. IE. checking will stop |
||
| 1653 | * at the previous semi-colon found. |
||
| 1654 | * |
||
| 1655 | * @return int|bool |
||
| 1656 | * @see findNext() |
||
| 1657 | */ |
||
| 1658 | public function findPrevious( |
||
| 1711 | |||
| 1712 | |||
| 1713 | /** |
||
| 1714 | * Returns the position of the next specified token(s). |
||
| 1715 | * |
||
| 1716 | * If a value is specified, the next token of the specified type(s) |
||
| 1717 | * containing the specified value will be returned. |
||
| 1718 | * |
||
| 1719 | * Returns false if no token can be found. |
||
| 1720 | * |
||
| 1721 | * @param int|array $types The type(s) of tokens to search for. |
||
| 1722 | * @param int $start The position to start searching from in the |
||
| 1723 | * token stack. |
||
| 1724 | * @param int $end The end position to fail if no token is found. |
||
| 1725 | * if not specified or null, end will default to |
||
| 1726 | * the end of the token stack. |
||
| 1727 | * @param bool $exclude If true, find the next token that is NOT of |
||
| 1728 | * a type specified in $types. |
||
| 1729 | * @param string $value The value that the token(s) must be equal to. |
||
| 1730 | * If value is omitted, tokens with any value will |
||
| 1731 | * be returned. |
||
| 1732 | * @param bool $local If true, tokens outside the current statement |
||
| 1733 | * will not be checked. i.e., checking will stop |
||
| 1734 | * at the next semi-colon found. |
||
| 1735 | * |
||
| 1736 | * @return int|bool |
||
| 1737 | * @see findPrevious() |
||
| 1738 | */ |
||
| 1739 | public function findNext( |
||
| 1778 | |||
| 1779 | |||
| 1780 | /** |
||
| 1781 | * Returns the position of the first non-whitespace token in a statement. |
||
| 1782 | * |
||
| 1783 | * @param int $start The position to start searching from in the token stack. |
||
| 1784 | * @param int|array $ignore Token types that should not be considered stop points. |
||
| 1785 | * |
||
| 1786 | * @return int |
||
| 1787 | */ |
||
| 1788 | public function findStartOfStatement($start, $ignore=null) |
||
| 1843 | |||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * Returns the position of the last non-whitespace token in a statement. |
||
| 1847 | * |
||
| 1848 | * @param int $start The position to start searching from in the token stack. |
||
| 1849 | * @param int|array $ignore Token types that should not be considered stop points. |
||
| 1850 | * |
||
| 1851 | * @return int |
||
| 1852 | */ |
||
| 1853 | public function findEndOfStatement($start, $ignore=null) |
||
| 1918 | |||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Returns the position of the first token on a line, matching given type. |
||
| 1922 | * |
||
| 1923 | * Returns false if no token can be found. |
||
| 1924 | * |
||
| 1925 | * @param int|array $types The type(s) of tokens to search for. |
||
| 1926 | * @param int $start The position to start searching from in the |
||
| 1927 | * token stack. The first token matching on |
||
| 1928 | * this line before this token will be returned. |
||
| 1929 | * @param bool $exclude If true, find the token that is NOT of |
||
| 1930 | * the types specified in $types. |
||
| 1931 | * @param string $value The value that the token must be equal to. |
||
| 1932 | * If value is omitted, tokens with any value will |
||
| 1933 | * be returned. |
||
| 1934 | * |
||
| 1935 | * @return int | bool |
||
| 1936 | */ |
||
| 1937 | public function findFirstOnLine($types, $start, $exclude=false, $value=null) |
||
| 1977 | |||
| 1978 | |||
| 1979 | /** |
||
| 1980 | * Determine if the passed token has a condition of one of the passed types. |
||
| 1981 | * |
||
| 1982 | * @param int $stackPtr The position of the token we are checking. |
||
| 1983 | * @param int|array $types The type(s) of tokens to search for. |
||
| 1984 | * |
||
| 1985 | * @return boolean |
||
| 1986 | */ |
||
| 1987 | public function hasCondition($stackPtr, $types) |
||
| 2012 | |||
| 2013 | |||
| 2014 | /** |
||
| 2015 | * Return the position of the condition for the passed token. |
||
| 2016 | * |
||
| 2017 | * Returns FALSE if the token does not have the condition. |
||
| 2018 | * |
||
| 2019 | * @param int $stackPtr The position of the token we are checking. |
||
| 2020 | * @param int $type The type of token to search for. |
||
| 2021 | * |
||
| 2022 | * @return int |
||
| 2023 | */ |
||
| 2024 | public function getCondition($stackPtr, $type) |
||
| 2046 | |||
| 2047 | |||
| 2048 | /** |
||
| 2049 | * Returns the name of the class that the specified class extends. |
||
| 2050 | * |
||
| 2051 | * Returns FALSE on error or if there is no extended class name. |
||
| 2052 | * |
||
| 2053 | * @param int $stackPtr The stack position of the class. |
||
| 2054 | * |
||
| 2055 | * @return string |
||
| 2056 | */ |
||
| 2057 | public function findExtendedClassName($stackPtr) |
||
| 2095 | |||
| 2096 | |||
| 2097 | }//end class |
||
| 2098 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.