Skip to content

Commit c436252

Browse files
committed
Merge branch 'feature/exception-consistency' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 3e18c86 + 35b8bd7 commit c436252

File tree

16 files changed

+47
-26
lines changed

16 files changed

+47
-26
lines changed

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
4444
- JSON reports now end with a newline character
4545
- The phpcs.xsd schema now validates phpcs-only and phpcbf-only attributes correctly
4646
-- Thanks to Juliette Reinders Folmer for the patch
47+
- All helper methods inside the File class now throw RuntimeException instead of TokenizerException
48+
-- Some tokenizer methods were also throwing RuntimeExpection but now correctly throw TokenizerException
49+
-- Thanks to Juliette Reinders Folmer for the patch
4750
- The File::getMethodParameters() method now returns more information, and supports closure USE groups
4851
-- If a type hint is specified, the position of the last token in the hint will be set in a "type_hint_end_token" array index
4952
-- If a default is specified, the position of the first token in the default value will be set in a "default_token" array index

src/Config.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ public function restoreDefaults()
584584
* @param int $pos The position of the argument on the command line.
585585
*
586586
* @return void
587+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
587588
*/
588589
public function processShortArgument($arg, $pos)
589590
{
@@ -688,6 +689,7 @@ public function processShortArgument($arg, $pos)
688689
* @param int $pos The position of the argument on the command line.
689690
*
690691
* @return void
692+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
691693
*/
692694
public function processLongArgument($arg, $pos)
693695
{
@@ -1249,6 +1251,7 @@ public function processLongArgument($arg, $pos)
12491251
* @param int $pos The position of the argument on the command line.
12501252
*
12511253
* @return void
1254+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
12521255
*/
12531256
public function processUnknownArgument($arg, $pos)
12541257
{
@@ -1274,6 +1277,7 @@ public function processUnknownArgument($arg, $pos)
12741277
* @param string $path The path to the file to add.
12751278
*
12761279
* @return void
1280+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
12771281
*/
12781282
public function processFilePath($path)
12791283
{
@@ -1560,7 +1564,7 @@ public static function getExecutablePath($name)
15601564
*
15611565
* @return bool
15621566
* @see getConfigData()
1563-
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the config file can not be written.
1567+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the config file can not be written.
15641568
*/
15651569
public static function setConfigData($key, $value, $temp=false)
15661570
{
@@ -1641,6 +1645,7 @@ public static function setConfigData($key, $value, $temp=false)
16411645
*
16421646
* @return array<string, string>
16431647
* @see getConfigData()
1648+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the config file could not be read.
16441649
*/
16451650
public static function getAllConfigData()
16461651
{

src/Files/File.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,22 +1303,22 @@ public function getDeclarationName($stackPtr)
13031303
* to acquire the parameters for.
13041304
*
13051305
* @return array
1306-
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1307-
* type T_FUNCTION or T_CLOSURE.
1306+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified $stackPtr is not of
1307+
* type T_FUNCTION, T_CLOSURE, or T_USE.
13081308
*/
13091309
public function getMethodParameters($stackPtr)
13101310
{
13111311
if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
13121312
&& $this->tokens[$stackPtr]['code'] !== T_CLOSURE
13131313
&& $this->tokens[$stackPtr]['code'] !== T_USE
13141314
) {
1315-
throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE or T_USE');
1315+
throw new RuntimeException('$stackPtr must be of type T_FUNCTION or T_CLOSURE or T_USE');
13161316
}
13171317

13181318
if ($this->tokens[$stackPtr]['code'] === T_USE) {
13191319
$opener = $this->findNext(T_OPEN_PARENTHESIS, ($stackPtr + 1));
13201320
if ($opener === false || isset($this->tokens[$opener]['parenthesis_owner']) === true) {
1321-
throw new TokenizerException('$stackPtr was not a valid T_USE');
1321+
throw new RuntimeException('$stackPtr was not a valid T_USE');
13221322
}
13231323
} else {
13241324
$opener = $this->tokens[$stackPtr]['parenthesis_opener'];
@@ -1530,15 +1530,15 @@ public function getMethodParameters($stackPtr)
15301530
* acquire the properties for.
15311531
*
15321532
* @return array
1533-
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1534-
* T_FUNCTION token.
1533+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a
1534+
* T_FUNCTION token.
15351535
*/
15361536
public function getMethodProperties($stackPtr)
15371537
{
15381538
if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
15391539
&& $this->tokens[$stackPtr]['code'] !== T_CLOSURE
15401540
) {
1541-
throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1541+
throw new RuntimeException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
15421542
}
15431543

15441544
if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
@@ -1684,14 +1684,14 @@ public function getMethodProperties($stackPtr)
16841684
* acquire the properties for.
16851685
*
16861686
* @return array
1687-
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1688-
* T_VARIABLE token, or if the position is not
1689-
* a class member variable.
1687+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a
1688+
* T_VARIABLE token, or if the position is not
1689+
* a class member variable.
16901690
*/
16911691
public function getMemberProperties($stackPtr)
16921692
{
16931693
if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1694-
throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1694+
throw new RuntimeException('$stackPtr must be of type T_VARIABLE');
16951695
}
16961696

16971697
$conditions = array_keys($this->tokens[$stackPtr]['conditions']);
@@ -1716,7 +1716,7 @@ public function getMemberProperties($stackPtr)
17161716
return [];
17171717
}
17181718
} else {
1719-
throw new TokenizerException('$stackPtr is not a class member var');
1719+
throw new RuntimeException('$stackPtr is not a class member var');
17201720
}
17211721
}
17221722

@@ -1728,7 +1728,7 @@ public function getMemberProperties($stackPtr)
17281728
&& isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
17291729
&& $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
17301730
) {
1731-
throw new TokenizerException('$stackPtr is not a class member var');
1731+
throw new RuntimeException('$stackPtr is not a class member var');
17321732
}
17331733
}
17341734

@@ -1847,13 +1847,13 @@ public function getMemberProperties($stackPtr)
18471847
* acquire the properties for.
18481848
*
18491849
* @return array
1850-
* @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1851-
* T_CLASS token.
1850+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position is not a
1851+
* T_CLASS token.
18521852
*/
18531853
public function getClassProperties($stackPtr)
18541854
{
18551855
if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1856-
throw new TokenizerException('$stackPtr must be of type T_CLASS');
1856+
throw new RuntimeException('$stackPtr must be of type T_CLASS');
18571857
}
18581858

18591859
$valid = [
@@ -2034,6 +2034,7 @@ public function isReference($stackPtr)
20342034
* content should be used.
20352035
*
20362036
* @return string The token contents.
2037+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified position does not exist.
20372038
*/
20382039
public function getTokensAsString($start, $length, $origContent=false)
20392040
{

src/Files/FileList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public function addFile($path, $file=null)
136136
* Get the class name of the filter being used for the run.
137137
*
138138
* @return string
139+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the specified filter could not be found.
139140
*/
140141
private function getFilterClass()
141142
{

src/Reporter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class Reporter
9292
* @param \PHP_CodeSniffer\Config $config The config data for the run.
9393
*
9494
* @return void
95-
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If a report is not available.
95+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException If a custom report class could not be found.
96+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If a report class is incorrectly set up.
9697
*/
9798
public function __construct(Config $config)
9899
{

src/Reports/Cbf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Cbf implements Report
3434
* @param int $width Maximum allowed line width.
3535
*
3636
* @return bool
37+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
3738
*/
3839
public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
3940
{

src/Reports/Gitblame.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected function getAuthor($line)
6363
* @param string $filename File to blame.
6464
*
6565
* @return array
66+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
6667
*/
6768
protected function getBlameContent($filename)
6869
{

src/Reports/Hgblame.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ protected function getAuthor($line)
6464
* @param string $filename File to blame.
6565
*
6666
* @return array
67+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
6768
*/
6869
protected function getBlameContent($filename)
6970
{

src/Reports/Svnblame.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function getAuthor($line)
4949
* @param string $filename File to blame.
5050
*
5151
* @return array
52+
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException
5253
*/
5354
protected function getBlameContent($filename)
5455
{

src/Ruleset.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Ruleset
122122
* @param \PHP_CodeSniffer\Config $config The config data for the run.
123123
*
124124
* @return void
125+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If no sniffs were registered.
125126
*/
126127
public function __construct(Config $config)
127128
{
@@ -304,7 +305,8 @@ public function explain()
304305
* is only used for debug output.
305306
*
306307
* @return string[]
307-
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the ruleset path is invalid.
308+
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException - If the ruleset path is invalid.
309+
* - If a specified autoload file could not be found.
308310
*/
309311
public function processRuleset($rulesetPath, $depth=0)
310312
{

0 commit comments

Comments
 (0)