ComposerLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A obtainVendorDir() 0 5 1
A getLoader() 0 3 1
A __construct() 0 7 1
A __invoke() 0 3 1
A addComposerNamespaces() 0 3 1
1
<?php
2
3
namespace BFW\Core\AppSystems;
4
5
class ComposerLoader extends AbstractSystem
6
{
7
    /**
8
     * @var \Composer\Autoload\ClassLoader $loader Composer auto-loader
9
     */
10
    protected $loader;
11
    
12
    /**
13
     * Define loader property and add all namespaces
14
     */
15
    public function __construct()
16
    {
17
        $this->loader = require(
18
            $this->obtainVendorDir().'autoload.php'
19
        );
20
21
        $this->addComposerNamespaces();
22
    }
23
    
24
    /**
25
     * {@inheritdoc}
26
     * 
27
     * @return \Composer\Autoload\ClassLoader
28
     */
29
    public function __invoke()
30
    {
31
        return $this->loader;
32
    }
33
    
34
    /**
35
     * Getter accessor to property loader
36
     * 
37
     * @return \Composer\Autoload\ClassLoader
38
     */
39
    public function getLoader()
40
    {
41
        return $this->loader;
42
    }
43
    
44
    /**
45
     * Return the path to the vendor directory
46
     * 
47
     * @return string
48
     */
49
    protected function obtainVendorDir(): string
50
    {
51
        return \BFW\Application::getInstance()
52
            ->getOptions()
53
            ->getValue('vendorDir')
54
        ;
55
    }
56
57
    /**
58
     * Add namespaces used by a BFW Application to composer
59
     * 
60
     * @return void
61
     */
62
    protected function addComposerNamespaces()
63
    {
64
        $this->loader->addPsr4('Modules\\', MODULES_ENABLED_DIR);
0 ignored issues
show
Bug introduced by
The constant BFW\Core\AppSystems\MODULES_ENABLED_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
    }
66
}
67