Completed
Branch master (766f26)
by Elf
04:56 queued 03:40
created

helpers.php ➔ app_id()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 0
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use ElfSundae\Laravel\Apps\AppIdentifier;
4
5
if (! function_exists('app_id')) {
6
    /**
7
     * Get or check the current application identifier.
8
     *
9
     * @return string|bool
10
     */
11
    function app_id()
12
    {
13 1
        $identifier = AppIdentifier::get();
14
15 1
        if (func_num_args() > 0) {
16 1
            return in_array($identifier, is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args());
17
        }
18
19 1
        return $identifier;
20
    }
21
}
22
23
if (! function_exists('app_url')) {
24
    /**
25
     * Generate an absolute URL to the given path.
26
     *
27
     * @param  string  $path
28
     * @param  mixed  $query
29
     * @param  mixed  $identifier
30
     * @return string
31
     */
32
    function app_url($path = '', $query = [], $identifier = '')
33
    {
34 1
        if (is_string($query)) {
35 1
            list($query, $identifier) = [$identifier, $query];
36
        }
37
38 1
        $url = config("apps.url.$identifier", config('app.url'));
39
40 1
        if ($path = ltrim($path, '/')) {
41 1
            $url .= (strpos($path, '?') === 0 ? '' : '/').$path;
42
        }
43
44 1
        if ($query && $query = http_build_query($query, '', '&', PHP_QUERY_RFC3986)) {
45 1
            $url .= (strpos($url, '?') === false ? '?' : '&').$query;
46
        }
47
48 1
        return $url;
49
    }
50
}
51