testErrorIsThrownInNonExistentMethods()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace skrtdev\PrototypesTests;
4
5
use Error;
6
use PHPUnit\Framework\TestCase;
7
use skrtdev\Prototypes\Exception;
8
9
10
class PrototypesTest extends TestCase
11
{
12
    public function testPrototypeCanBeCreated(): void
13
    {
14
        $this->assertNull(DemoClassTest::addMethod('prototypeMethod', fn() => $this->property));
0 ignored issues
show
Bug introduced by
Are you sure the usage of skrtdev\PrototypesTests\...ion(...) { /* ... */ }) targeting skrtdev\PrototypesTests\DemoClassTest::addMethod() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
The property property does not exist on skrtdev\PrototypesTests\PrototypesTest. Did you mean prophet?
Loading history...
15
    }
16
17
    public function testPrototypeCanBeCalled(): void
18
    {
19
        $this->assertTrue((new DemoClassTest)->prototypeMethod());
0 ignored issues
show
Bug introduced by
The method prototypeMethod() does not exist on skrtdev\PrototypesTests\DemoClassTest. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        $this->assertTrue((new DemoClassTest)->/** @scrutinizer ignore-call */ prototypeMethod());
Loading history...
20
    }
21
22
    public function testErrorIsThrownInNonExistentMethods(): void
23
    {
24
        $this->expectException(Error::class);
25
        (new DemoClassTest)->nonExistentMethod();
0 ignored issues
show
Bug introduced by
The method nonExistentMethod() does not exist on skrtdev\PrototypesTests\DemoClassTest. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        (new DemoClassTest)->/** @scrutinizer ignore-call */ nonExistentMethod();
Loading history...
26
    }
27
28
    public function testCantOverridePrototypes(): void
29
    {
30
        $this->expectException(Exception::class);
31
        DemoClassTest::addMethod('prototypeMethod', fn() => $this->property);
0 ignored issues
show
Bug introduced by
The property property does not exist on skrtdev\PrototypesTests\PrototypesTest. Did you mean prophet?
Loading history...
32
    }
33
34
    public function testCantOverrideMethods(): void
35
    {
36
        $this->expectException(Exception::class);
37
        DemoClassTest::addMethod('existentMethod', fn() => $this->property);
0 ignored issues
show
Bug introduced by
The property property does not exist on skrtdev\PrototypesTests\PrototypesTest. Did you mean prophet?
Loading history...
38
    }
39
40
    public function testCanUseCallable(): void
41
    {
42
        $this->assertNull(DemoClassTest::addMethod('unexistentMethod', 'file_get_contents'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of skrtdev\PrototypesTests\...', 'file_get_contents') targeting skrtdev\PrototypesTests\DemoClassTest::addMethod() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
    }
44
45
    public function testCanUseNamedArguments(): void
46
    {
47
        DemoClassTest::addMethod('methodWithNamedArguments', function (int $named_argument){
48
            return $named_argument;
49
        });
50
        $this->assertEquals(12, (new DemoClassTest)->methodWithNamedArguments(named_argument: 12));
0 ignored issues
show
Bug introduced by
The method methodWithNamedArguments() does not exist on skrtdev\PrototypesTests\DemoClassTest. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $this->assertEquals(12, (new DemoClassTest)->/** @scrutinizer ignore-call */ methodWithNamedArguments(named_argument: 12));
Loading history...
51
        $this->assertEquals(12, (new DemoClassTest)->methodWithNamedArguments(...['named_argument' => 12]));
52
    }
53
54
}
55