AnnotationLoader::getVendorPath()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
3
namespace Fousky\Component\iDoklad\Util;
4
5
use Composer\Autoload\ClassLoader;
6
use Doctrine\Common\Annotations\AnnotationRegistry;
7
8
/**
9
 * Register Doctrine annotations for Validator.
10
 *
11
 * @author Lukáš Brzák <[email protected]>
12
 */
13
class AnnotationLoader
14
{
15
    /** @var bool $_init */
16
    protected static $_init = false;
17
18
    /**
19
     * @throws \RuntimeException
20
     * @throws \ReflectionException
21
     * @throws \InvalidArgumentException
22
     */
23
    public static function init()
24
    {
25
        if (false === static::$_init) {
26
            // inject Composer autoloader inside Doctrine annotation reader.
27
            AnnotationRegistry::registerLoader([
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...istry::registerLoader() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
28
                require sprintf('%s/autoload.php', static::getVendorPath()),
29
                'loadClass',
30
            ]);
31
32
            static::$_init = true;
33
        }
34
    }
35
36
    /**
37
     * @throws \ReflectionException
38
     * @throws \RuntimeException
39
     *
40
     * @return string
41
     */
42
    protected static function getVendorPath(): string
43
    {
44
        $reflector = new \ReflectionClass(ClassLoader::class);
45
        $vendorPath = preg_replace('/^(.*)\/composer\/ClassLoader\.php$/', '$1', $reflector->getFileName());
46
47
        if ($vendorPath && is_dir($vendorPath)) {
48
            return rtrim($vendorPath, '/');
49
        }
50
51
        throw new \RuntimeException('Unable to detect vendor path.');
52
    }
53
}
54