From 0dd9e2daf7037e00bfc78e5670635e8a65731fad Mon Sep 17 00:00:00 2001 From: fschmtt Date: Thu, 22 Aug 2019 08:30:43 +0200 Subject: [PATCH] Allow mysqli, mysqli_driver, mysqli_result, mysqli_stmt, mysqli_sql_exception and mysqli_warning as return types --- .../Sniffs/Docblock/ReturnTypeSniff.php | 19 ++++++- tests/rules/doc/allowed/ReturnTypeMysqli.php | 50 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests/rules/doc/allowed/ReturnTypeMysqli.php diff --git a/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php b/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php index 3d92aea..6271637 100644 --- a/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php +++ b/custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php @@ -20,10 +20,22 @@ class ReturnTypeSniff implements Sniff 'bool[]', 'int[]', 'string[]', - 'float[]', + 'float[]', 'null' ]; + /** + * @var array + */ + private $returnTypeClassWhitelist = [ + 'mysqli', + 'mysqli_driver', + 'mysqli_result', + 'mysqli_stmt', + 'mysqli_sql_exception', + 'mysqli_warning', + ]; + /** * @return array */ @@ -50,7 +62,10 @@ public function process(File $phpcsFile, $stackPtr) foreach ($returnTypes as $returnType) { $returnType = trim($returnType); - if (in_array($returnType, $this->returnTypeScalarWhitelist)) { + if (in_array($returnType, $this->returnTypeScalarWhitelist, true)) { + continue; + } + if (in_array($returnType, $this->returnTypeClassWhitelist, true)) { continue; } if ($this->isStartingWithUppercaseLetter($returnType)) { diff --git a/tests/rules/doc/allowed/ReturnTypeMysqli.php b/tests/rules/doc/allowed/ReturnTypeMysqli.php new file mode 100644 index 0000000..8412441 --- /dev/null +++ b/tests/rules/doc/allowed/ReturnTypeMysqli.php @@ -0,0 +1,50 @@ +