diff --git a/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php b/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php
index 88e0b13..3dd7e32 100644
--- a/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php
+++ b/SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php
@@ -44,11 +44,7 @@ public function register()
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
- if (in_array(
- $tokens[$stackPtr]['content'],
- $this->tags
- )
- ) {
+ if (in_array($tokens[$stackPtr]['content'], $this->tags)) {
$phpcsFile->addError(
'The %s annotation is forbidden to use',
$stackPtr,
diff --git a/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php b/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php
index 1e6a81b..da2420f 100644
--- a/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php
+++ b/SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php
@@ -118,12 +118,8 @@ public function process(File $phpcsFile, $stackPtr)
*
* @return void
*/
- protected function processReturn(
- File $phpcsFile,
- $stackPtr,
- $commentStart,
- $hasComment = true
- ) {
+ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart, $hasComment = true)
+ {
// Check for inheritDoc if there is comment
if ($hasComment && $this->isInheritDoc($phpcsFile, $stackPtr)) {
return;
@@ -166,16 +162,51 @@ protected function processReturn(
}
}
+ /**
+ * @param File $phpcsFile
+ * @param int $stackPtr
+ * @param int $commentStart
+ */
+ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
+ {
+ $tokens = $phpcsFile->getTokens();
+
+ $throw = null;
+ foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
+ if ('@throws' === $tokens[$tag]['content']) {
+ if (null !== $throw) {
+ $error = 'Only 1 @throws tag is allowed in a function comment';
+ $phpcsFile->addError($error, $tag, 'DuplicateThrow');
+
+ return;
+ }
+
+ $throw = $tag;
+ }
+ }
+
+ if (null !== $throw) {
+ $exception = null;
+ if (T_DOC_COMMENT_STRING === $tokens[($throw + 2)]['code']) {
+ $matches = [];
+ preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[($throw + 2)]['content'], $matches);
+ $exception = $matches[1];
+ }
+
+ if (null === $exception) {
+ $error = 'Exception type missing for @throws tag in function comment';
+ $phpcsFile->addError($error, $throw, 'InvalidThrows');
+ }
+ }
+ }
+
/**
* @param File $phpcsFile
* @param int $commentStart
* @param bool $hasComment
*/
- protected function processWhitespace(
- File $phpcsFile,
- $commentStart,
- $hasComment = true
- ) {
+ protected function processWhitespace(File $phpcsFile, $commentStart, $hasComment = true)
+ {
$tokens = $phpcsFile->getTokens();
$before = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
@@ -249,11 +280,8 @@ protected function isInheritDoc(File $phpcsFile, $stackPtr)
*
* @return void
*/
- protected function processParams(
- File $phpcsFile,
- $stackPtr,
- $commentStart
- ) {
+ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
+ {
if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
return;
}
diff --git a/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php b/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php
index aa1aca4..264c697 100644
--- a/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php
+++ b/SymfonyCustom/Sniffs/NamingConventions/ValidFileNameSniff.php
@@ -36,8 +36,8 @@ public function process(File $phpcsFile, $stackPtr)
return;
}
- $filenamePhp = str_replace('_', '', basename($filename, '.php'));
- $filenameInc = str_replace('_', '', basename($filename, '.inc'));
+ $filenamePhp = basename($filename, '.php');
+ $filenameInc = basename($filename, '.inc');
if (strlen($filenameInc) < strlen($filenamePhp)) {
$filename = $filenameInc;
diff --git a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc
index ed81bca..f75ee39 100644
--- a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc
+++ b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc
@@ -103,3 +103,28 @@ function toIgnore2()
{
$test = 42;
}
+
+/**
+ * @throws Exception
+ */
+function throwTest()
+{
+ throw new Exception();
+}
+
+/**
+ * @throws Exception|RuntimeException
+ */
+function throwTest2()
+{
+ throw new Exception();
+}
+
+/**
+ * @throws Exception
+ * @throws RuntimeException
+ */
+function throwTest3()
+{
+ throw new Exception();
+}
diff --git a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc.fixed
index 40b160b..8e26488 100644
--- a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc.fixed
+++ b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.inc.fixed
@@ -107,3 +107,28 @@ function toIgnore2()
{
$test = 42;
}
+
+/**
+ * @throws Exception
+ */
+function throwTest()
+{
+ throw new Exception();
+}
+
+/**
+ * @throws Exception|RuntimeException
+ */
+function throwTest2()
+{
+ throw new Exception();
+}
+
+/**
+ * @throws Exception
+ * @throws RuntimeException
+ */
+function throwTest3()
+{
+ throw new Exception();
+}
diff --git a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php
index b195110..feadc09 100644
--- a/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php
+++ b/SymfonyCustom/Tests/Commenting/FunctionCommentUnitTest.php
@@ -30,6 +30,7 @@ public function getErrorList()
83 => 1,
93 => 1,
102 => 1,
+ 125 => 1,
];
}
diff --git a/SymfonyCustom/ruleset.xml b/SymfonyCustom/ruleset.xml
index c82e4ee..ae828fa 100755
--- a/SymfonyCustom/ruleset.xml
+++ b/SymfonyCustom/ruleset.xml
@@ -39,34 +39,19 @@
-
-
-
+
+
+
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
@@ -82,15 +67,32 @@
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
-
+
+
+
+
+
diff --git a/docs/php.md b/docs/php.md
index acc1cfd..8c5198c 100644
--- a/docs/php.md
+++ b/docs/php.md
@@ -47,104 +47,7 @@ we do not respect this rule:
## Others
### Imported
-- Do not use `` to define a PHP file
-
-```
-
-```
-
-- Add a single space after type casting
-
-```
-
-```
-
-- Do not use space inside type casting
-
-```
-
-```
-
-- Use lowercase for PHP functions
-
-```
-
-```
-
-- Variable have scope modifier
-
-```
-
-```
-
-- No perl-style comments are used
-
-```
-
-```
-
-- Use single quotes instead of double quotes
-
-```
-
-
-
-```
-
-- Do not skip blank line after function opening brace
-
-```
-
-```
-
-- Do not use space before semicolon
-
-```
-
-```
-
-- Do not use `error_log`, `print_r`, `var_dump`, `sizeof`, `delete`, `print`, `is_null` and `create_function`
-
-```
-
-
-```
-
-- Use short array syntax
-
-```
-
-```
-
-- Do not use empty PHP statement
-
-```
-
-```
-
-- Add a single space around logical operator (`&&`, `||`, `...`)
-
-```
-
-```
-
-- Do not use space around object operators (`->`)
-
-```
-
-
-
-
-
-```
-
-- DocComment should be correctly indented
-
-```
-
-
-
-```
+*See `ruleset.xml` for up to date configuration.*
### Custom
- Some others checks are made about array (`=>` alignments and indentation)
@@ -153,47 +56,47 @@ we do not respect this rule:
```
-- Do not use spaces after `(`, `{` or `[` and before `)`, `}` or `]`
+- Do not use blank lines after class openers `{`
```
-
-
+
```
-- Do not use blank lines after class openers `{`
+- Member var should have phpDoc with one blank line before
```
-
+
```
-- Do not use multiple following blank lines
+- `use` keywords should be alphabetically sorted
```
-
+
```
-- Methods have scope modifier
+- Add a single space before `namespace` declaration
```
-
+
```
-- Member var should have phpDoc with one blank line before
+- Unused `use` statement should be removed
```
-
+
```
-- `use` keywords should be alphabetically sorted
+- Methods have scope modifier
```
-
+
```
-- Unused `use` statement should be removed
+- Do not use spaces after `(`, `{` or `[` and before `)`, `}` or `]`
```
-
+
+
```
- Add a single space around comment tag (`@var`, `@return`, `...`)
@@ -202,8 +105,8 @@ we do not respect this rule:
```
-- Add a single space before `namespace` declaration
+- Do not use multiple following blank lines
```
-
+
```