Skip to content

Commit

Permalink
Allow Multiple try-catch classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CMalvika committed Jan 11, 2018
1 parent 0bdf4da commit 5366c7d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/InterNations/Sniffs/Naming/ConstantNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ public function process(File $file, $stackPtr)
return;
}

// Is it a catch block
$prevPtrCatch = $file->findPrevious([T_WHITESPACE, T_OPEN_PARENTHESIS], ($stackPtr - 1), null, true);
if ($tokens[$prevPtrCatch]['code'] === T_CATCH) {
return;
}

// This is a real constant.
if (strtoupper($constName) !== $constName) {
$error = 'Constants must be uppercase; expected %s but found %s';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ public function testConstants(): void
'Class constants for event types must be camelcase and start with "on", "before" or "after". Found onAfterInvalid'
);
}

public function testMultipleCatchBlocks(): void
{
$file = __DIR__ . '/Fixtures/ConstantName/MultipleCatchBlocks.php';
$errors = $this->analyze(['InterNations/Sniffs/Naming/ConstantNameSniff'], [$file]);

$this->assertReportCount(0, 0, $errors, $file);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
use const Foo\Bar\BAZ;
use function Foo\funcName;


class Clazz
{
public function lalala()
{
try {
// Try block
} catch (FirstException | SecondException $e) {
// Multiple catch block
}
}
}

0 comments on commit 5366c7d

Please sign in to comment.