Passed
Pull Request — 1.x (#2)
by Akihito
11:09 queued 09:15
created

Spy::newInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\TestDouble;
6
7
use Ray\Aop\Bind;
8
use Ray\Aop\Weaver;
9
10
use function sys_get_temp_dir;
11
12
final class Spy
13
{
14
    private string $tmpDir;
15
16
    public function __construct(string|null $tmpDir = null)
17
    {
18
        $this->tmpDir = $tmpDir ?? sys_get_temp_dir();
19
    }
20
21
    /**
22
     * @param class-string<T> $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
23
     *
24
     * @return T
25
     *
26
     * @template T of object
27
     */
28
    public function newInstance(string $class, string $method, Logger $spyLog): object
29
    {
30
        $bind = (new Bind())->bindInterceptors($method, [new SpyInterceptor($spyLog)]);
31
        $compiler = new Weaver($bind, $this->tmpDir);
32
33
        return $compiler->newInstance($class, []);
34
    }
35
}
36