Skip to content

Commit 0dd9e2d

Browse files
committed
Allow mysqli, mysqli_driver, mysqli_result, mysqli_stmt, mysqli_sql_exception and mysqli_warning as return types
1 parent 400ae29 commit 0dd9e2d

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

custom-standards/Flyeralarm/Sniffs/Docblock/ReturnTypeSniff.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ class ReturnTypeSniff implements Sniff
2020
'bool[]',
2121
'int[]',
2222
'string[]',
23-
'float[]',
23+
'float[]',
2424
'null'
2525
];
2626

27+
/**
28+
* @var array
29+
*/
30+
private $returnTypeClassWhitelist = [
31+
'mysqli',
32+
'mysqli_driver',
33+
'mysqli_result',
34+
'mysqli_stmt',
35+
'mysqli_sql_exception',
36+
'mysqli_warning',
37+
];
38+
2739
/**
2840
* @return array
2941
*/
@@ -50,7 +62,10 @@ public function process(File $phpcsFile, $stackPtr)
5062

5163
foreach ($returnTypes as $returnType) {
5264
$returnType = trim($returnType);
53-
if (in_array($returnType, $this->returnTypeScalarWhitelist)) {
65+
if (in_array($returnType, $this->returnTypeScalarWhitelist, true)) {
66+
continue;
67+
}
68+
if (in_array($returnType, $this->returnTypeClassWhitelist, true)) {
5469
continue;
5570
}
5671
if ($this->isStartingWithUppercaseLetter($returnType)) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
// @expectedPass
4+
5+
namespace flyeralarm\Test;
6+
7+
class FooTest
8+
{
9+
/**
10+
* @return mysqli
11+
*/
12+
public function testMysqli()
13+
{
14+
}
15+
16+
/**
17+
* @return mysqli_driver
18+
*/
19+
public function testMysqliDriver()
20+
{
21+
}
22+
23+
/**
24+
* @return mysqli_result
25+
*/
26+
public function testMysqliResult()
27+
{
28+
}
29+
30+
/**
31+
* @return mysqli_stmt
32+
*/
33+
public function testMysqliStmt()
34+
{
35+
}
36+
37+
/**
38+
* @return mysqli_sql_exception
39+
*/
40+
public function testMysqliSqlException()
41+
{
42+
}
43+
44+
/**
45+
* @return mysqli_warning
46+
*/
47+
public function testMysqliWarning()
48+
{
49+
}
50+
}

0 commit comments

Comments
 (0)