1 | <?php |
||
2 | |||
3 | namespace LeKoala\DebugBar\Test\Extension; |
||
4 | |||
5 | use SilverStripe\Dev\SapphireTest; |
||
6 | use SilverStripe\ORM\DB; |
||
7 | use LeKoala\DebugBar\Extension\ProxyDBExtension; |
||
8 | use LeKoala\DebugBar\DebugBar; |
||
9 | |||
10 | class ProxyDBExtensionTest extends SapphireTest |
||
11 | { |
||
12 | /** |
||
13 | * @var SilverStripe\ORM\Connect\Database |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
14 | */ |
||
15 | protected $conn; |
||
16 | |||
17 | public function setUp(): void |
||
18 | { |
||
19 | parent::setUp(); |
||
20 | $this->conn = DB::get_conn(); |
||
0 ignored issues
–
show
It seems like
SilverStripe\ORM\DB::get_conn() can also be of type SilverStripe\ORM\Connect\Database . However, the property $conn is declared as type LeKoala\DebugBar\Test\Ex...pe\ORM\Connect\Database . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
21 | DebugBar::initDebugBar(); |
||
22 | } |
||
23 | |||
24 | public function testQueriesAreCollected() |
||
25 | { |
||
26 | $res = DebugBar::getDebugBar(); |
||
27 | $this->assertTrue($res !== false); |
||
28 | DB::query("SELECT 0"); |
||
29 | $this->assertNotEmpty(ProxyDBExtension::getQueries()); |
||
30 | ProxyDBExtension::resetQueries(); |
||
31 | } |
||
32 | } |
||
33 |