StaticPrototypesTest::testCantOverridePrototypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace skrtdev\PrototypesTests;
4
5
use Error;
6
use skrtdev\Prototypes\Exception;
7
use PHPUnit\Framework\TestCase;
8
9
class StaticPrototypesTest extends TestCase
10
{
11
12
    public function testPrototypeCanBeCreated(): void
13
    {
14
        $this->assertNull(DemoClassTest::addStaticMethod('prototypeStaticMethod', fn() => self::$static_property));
0 ignored issues
show
Bug introduced by
Are you sure the usage of skrtdev\PrototypesTests\...ion(...) { /* ... */ }) targeting skrtdev\PrototypesTests\...Test::addStaticMethod() 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 Best Practice introduced by
The property static_property does not exist on skrtdev\PrototypesTests\StaticPrototypesTest. Did you maybe forget to declare it?
Loading history...
15
    }
16
17
    public function testPrototypeCanBeCalled(): void
18
    {
19
        $this->assertTrue(DemoClassTest::prototypeStaticMethod());
0 ignored issues
show
Bug introduced by
The method prototypeStaticMethod() does not exist on skrtdev\PrototypesTests\DemoClassTest. Since you implemented __callStatic, 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(DemoClassTest::/** @scrutinizer ignore-call */ prototypeStaticMethod());
Loading history...
20
    }
21
22
    public function testErrorIsThrownInNonExistentMethods(): void
23
    {
24
        $this->expectException(Error::class);
25
        DemoClassTest::nonExistentStaticMethod();
0 ignored issues
show
Bug introduced by
The method nonExistentStaticMethod() does not exist on skrtdev\PrototypesTests\DemoClassTest. Since you implemented __callStatic, 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
        DemoClassTest::/** @scrutinizer ignore-call */ 
26
                       nonExistentStaticMethod();
Loading history...
26
    }
27
28
    public function testCantOverridePrototypes(): void
29
    {
30
        $this->expectException(Exception::class);
31
        DemoClassTest::addStaticMethod('prototypeStaticMethod', fn() => self::$static_property);
0 ignored issues
show
Bug Best Practice introduced by
The property static_property does not exist on skrtdev\PrototypesTests\StaticPrototypesTest. Did you maybe forget to declare it?
Loading history...
32
    }
33
34
    public function testCantOverrideMethods(): void
35
    {
36
        $this->expectException(Exception::class);
37
        DemoClassTest::addStaticMethod('existentStaticMethod', fn() => self::$static_property);
0 ignored issues
show
Bug Best Practice introduced by
The property static_property does not exist on skrtdev\PrototypesTests\StaticPrototypesTest. Did you maybe forget to declare it?
Loading history...
38
    }
39
40
    public function testCanUseNamedArguments(): void
41
    {
42
        DemoClassTest::addStaticMethod('staticMethodWithNamedArguments', function (int $named_argument){
43
            return $named_argument;
44
        });
45
        $this->assertEquals(12, DemoClassTest::staticMethodWithNamedArguments(named_argument: 12));
0 ignored issues
show
Bug introduced by
The method staticMethodWithNamedArguments() does not exist on skrtdev\PrototypesTests\DemoClassTest. Since you implemented __callStatic, 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

45
        $this->assertEquals(12, DemoClassTest::/** @scrutinizer ignore-call */ staticMethodWithNamedArguments(named_argument: 12));
Loading history...
46
        $this->assertEquals(12, DemoClassTest::staticMethodWithNamedArguments(...['named_argument' => 12]));
47
    }
48
49
}
50