Completed
Push — master ( d60d8f...cd7b4e )
by Koval
01:17
created

helpers.php ➔ get_namespace()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 0
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('app_path')) {
4
    /**
5
     * Get the path to the application folder.
6
     *
7
     * @param  string  $path
8
     * @return string
9
     */
10
    function app_path($path = '')
11
    {
12
        return app()->basePath($path);
13
    }
14
}
15
16
/**
17
 * Get the application namespace.
18
 *
19
 * @return string
20
 *
21
 * @throws \RuntimeException
22
 */
23
function get_namespace()
24
{
25
    $composer = json_decode(file_get_contents(base_path('composer.json')), true);
26
    
27
    foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path) {
28
        foreach ((array) $path as $pathChoice) {
29
            if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) {
30
                return $namespace;
31
            }
32
        }
33
    }
34
    
35
    throw new RuntimeException('Unable to detect application namespace.');
36
}