These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SubjectivePHPTest\Spl\Traits; |
||
4 | |||
5 | use SubjectivePHP\Spl\Traits\MagicPropertyDisabledTrait; |
||
6 | |||
7 | /** |
||
8 | * @coversDefaultClass SubjectivePHP\Spl\Traits\MagicPropertyDisabledTrait |
||
9 | */ |
||
10 | class MagicPropertyDisabledTraitTest extends \PHPUnit\Framework\TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @test |
||
14 | * @covers ::__get |
||
15 | * @expectedException \BadMethodCallException |
||
16 | */ |
||
17 | public function magicGet() |
||
18 | { |
||
19 | $object = $this->getObjectForTrait(MagicPropertyDisabledTrait::class); |
||
20 | $foo = $object->foo; |
||
0 ignored issues
–
show
$foo is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @test |
||
25 | * @covers ::__set |
||
26 | * @expectedException \BadMethodCallException |
||
27 | */ |
||
28 | public function magicSet() |
||
29 | { |
||
30 | $object = $this->getObjectForTrait(MagicPropertyDisabledTrait::class); |
||
31 | $object->foo = 'bar'; |
||
0 ignored issues
–
show
Accessing
foo on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
32 | } |
||
33 | } |
||
34 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: