ReflectionFilesystem::instance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-fuse package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Fuse\Filesystem;
15
16
use Fuse\FilesystemDefaultImplementationTrait;
17
use Fuse\FilesystemInterface;
18
use ReflectionClass;
19
20
final class ReflectionFilesystem
21
{
22
    private FilesystemInterface $filesystem;
23
24
    public function __construct(FilesystemInterface $filesystem)
25
    {
26
        $this->filesystem = $filesystem;
27
    }
28
29
    public static function instance(FilesystemInterface $filesystem): self
30
    {
31
        return new self($filesystem);
32
    }
33
34
    public function isDefault(string $method_name): bool
35
    {
36
        $class = new ReflectionClass($this->filesystem);
37
        $method = $class->getMethod($method_name);
38
        $trait = new ReflectionClass(FilesystemDefaultImplementationTrait::class);
39
        return $method->getFileName() === $trait->getFileName();
40
    }
41
}
42