Completed
Pull Request — 2.x (#158)
by Akihito
01:38
created

CachedClass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 (is_file($this->path) && ! class_exists($this->path, false)) {
32
            assert(file_exists($this->path)); // https://github.com/vimeo/psalm/issues/4788
33
            require $this->path;
34
35
            return true;
36
        }
37
38
        return false;
39
    }
40
}
41