Completed
Pull Request — 2.x (#158)
by Akihito
09:50 queued 07:31
created

CachedClass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A require() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Aop;
6
7
use function assert;
8
use function class_exists;
9
use function file_exists;
10
use function is_file;
11
12
final class CachedClass
13
{
14
    /** @var class-string */
15
    public $class;
16
17
    /** @var string */
18
    public $path;
19
20
    /**
21
     * @param class-string $class
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
22
     */
23
    public function __construct(string $class, string $path)
24
    {
25
        $this->class = $class;
26
        $this->path = $path;
27
    }
28
29
    public function require(): bool
30
    {
31
        if (class_exists($this->class, false)) {
32
            return true;
33
        }
34
35
        if (! is_file($this->path)) {
36
            return false;
37
        }
38
39
        assert(file_exists($this->path)); // https://github.com/vimeo/psalm/issues/4788
40
        require $this->path;
41
42
        return true;
43
    }
44
}
45