Test Failed
Pull Request — master (#108)
by
unknown
03:17
created

saml_idp_key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
if (!function_exists('saml_url'))
4
{
5
    /**
6
     * Generate a URL to saml/{key}/login which redirects to a target URL.
7
     *
8
     * @param string $path
9
     * @param string|null $key An IdP key.
10
     * @param array $parameters
11
     * @param bool $secure
12
     *
13
     * @return string
14
     */
15
    function saml_url(string $path, string $key = null, array $parameters = [], bool $secure = null)
16
    {
17
        $target = \Illuminate\Support\Facades\URL::to($path, $parameters, $secure);
18
19
        if(!$key) {
20
            if(!$key = saml_idp_key()) {
21
                return $target;
22
            }
23
        }
24
25
        return \Illuminate\Support\Facades\URL::route('saml.login', ['key' => $key, 'returnTo' => $target]);
26
    }
27
}
28
29
if (!function_exists('saml_route'))
30
{
31
    /**
32
     * Generate a URL to saml/{key}/login which redirects to a target route.
33
     *
34
     * @param string $name
35
     * @param string|null $key An IdP key.
36
     * @param array $parameters
37
     *
38
     * @return string
39
     */
40
    function saml_route(string $name, string $key = null, array $parameters = [])
41
    {
42
        $target = \Illuminate\Support\Facades\URL::route($name, $parameters, true);
43
44
        if(!$key) {
45
            if(!$key = saml_idp_key()) {
46
                return $target;
47
            }
48
        }
49
50
        return \Illuminate\Support\Facades\URL::route('saml.login', ['key' => $key, 'returnTo' => $target]);
51
    }
52
}
53
54
if (!function_exists('saml_idp_key'))
55
{
56
    /**
57
     * Get a resolved IdP key based on the current URL.
58
     *
59
     * @return string|null
60
     */
61
    function saml_idp_key()
62
    {
63
        return session()->get('saml2.idp.key');
0 ignored issues
show
Bug introduced by
The function session was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        return /** @scrutinizer ignore-call */ session()->get('saml2.idp.key');
Loading history...
64
    }
65
}
66