Passed
Push — master ( f872b6...81b6b5 )
by
unknown
04:25 queued 38s
created

parseQueryParameters()   F

Complexity

Conditions 13
Paths 1536

Size

Total Lines 40
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 40
rs 2.45
c 1
b 0
f 0
cc 13
nc 1536
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 *    simpleSAMLphp-casserver is a CAS 1.0 and 2.0 compliant CAS server in the form of a simpleSAMLphp module
5
 *
6
 *    Copyright (C) 2013  Bjorn R. Jensen
7
 *
8
 *    This library is free software; you can redistribute it and/or
9
 *    modify it under the terms of the GNU Lesser General Public
10
 *    License as published by the Free Software Foundation; either
11
 *    version 2.1 of the License, or (at your option) any later version.
12
 *
13
 *    This library is distributed in the hope that it will be useful,
14
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 *    Lesser General Public License for more details.
17
 *
18
 *    You should have received a copy of the GNU Lesser General Public
19
 *    License along with this library; if not, write to the Free Software
20
 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
 *
22
 */
23
24
declare(strict_types=1);
25
26
use SimpleSAML\Configuration;
27
use SimpleSAML\Module\casserver\Cas\ServiceValidator;
28
use SimpleSAML\Module\casserver\Cas\TicketValidator;
29
30
/**
31
 * @deprecated
32
 * @see ServiceValidator
33
 * @param string $service
34
 * @param array $legal_service_urls
35
 * @return bool
36
 */
37
function checkServiceURL(string $service, array $legal_service_urls): bool
38
{
39
    //delegate to ServiceValidator until all references to this can be cleaned up
40
    $config = Configuration::loadFromArray(['legal_service_urls' => $legal_service_urls]);
41
    $serviceValidator = new ServiceValidator($config);
42
    return $serviceValidator->checkServiceURL($service) !== null;
43
}
44
45
46
/**
47
 * @param string $parameter
48
 * @return string
49
 */
50
function sanitize(string $parameter): string
51
{
52
    return TicketValidator::sanitize($parameter);
53
}
54
55
56
/**
57
 * Parse the query Parameters from $_GET global and return them in an array.
58
 *
59
 * @param   array|null  $sessionTicket
60
 *
61
 * @return array
62
 */
63
function parseQueryParameters(?array $sessionTicket): array
64
{
65
    $forceAuthn = isset($_GET['renew']) && $_GET['renew'];
66
    $sessionRenewId = $sessionTicket ? $sessionTicket['renewId'] : null;
67
68
    $query = [];
69
70
    if ($sessionRenewId && $forceAuthn) {
71
        $query['renewId'] = $sessionRenewId;
72
    }
73
74
    if (isset($_REQUEST['service'])) {
75
        $query['service'] = $_REQUEST['service'];
76
    }
77
78
    if (isset($_REQUEST['TARGET'])) {
79
        $query['TARGET'] = $_REQUEST['TARGET'];
80
    }
81
82
    if (isset($_REQUEST['method'])) {
83
        $query['method'] = $_REQUEST['method'];
84
    }
85
86
    if (isset($_REQUEST['renew'])) {
87
        $query['renew'] = $_REQUEST['renew'];
88
    }
89
90
    if (isset($_REQUEST['gateway'])) {
91
        $query['gateway'] = $_REQUEST['gateway'];
92
    }
93
94
    if (array_key_exists('language', $_GET)) {
95
        $query['language'] = is_string($_GET['language']) ? $_GET['language'] : null;
96
    }
97
98
    if (isset($_REQUEST['debugMode'])) {
99
        $query['debugMode'] = $_REQUEST['debugMode'];
100
    }
101
102
    return $query;
103
}
104