Passed
Pull Request — master (#45)
by
unknown
15:00
created

UrlTrait::checkServiceURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\casserver\Controller\Traits;
6
7
use SimpleSAML\Configuration;
8
use SimpleSAML\Module\casserver\Cas\ServiceValidator;
9
use SimpleSAML\Module\casserver\Cas\TicketValidator;
10
use Symfony\Component\HttpFoundation\Request;
11
12
trait UrlTrait
13
{
14
    /**
15
     * @deprecated
16
     * @see ServiceValidator
17
     * @param string $service
18
     * @param array $legal_service_urls
19
     * @return bool
20
     */
21
    public function checkServiceURL(string $service, array $legal_service_urls): bool
22
    {
23
        //delegate to ServiceValidator until all references to this can be cleaned up
24
        $config = Configuration::loadFromArray(['legal_service_urls' => $legal_service_urls]);
25
        $serviceValidator = new ServiceValidator($config);
26
        return $serviceValidator->checkServiceURL($service) !== null;
27
    }
28
29
30
    /**
31
     * @param string $parameter
32
     * @return string
33
     */
34
    public function sanitize(string $parameter): string
35
    {
36
        return TicketValidator::sanitize($parameter);
37
    }
38
39
40
    /**
41
     * Parse the query Parameters from $_GET global and return them in an array.
42
     *
43
     * @param   array|null  $sessionTicket
44
     * @param   Request     $request
45
     *
46
     * @return array
47
     */
48
    public function parseQueryParameters(?array $sessionTicket, Request $request): array
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

48
    public function parseQueryParameters(?array $sessionTicket, /** @scrutinizer ignore-unused */ Request $request): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $forceAuthn = isset($_GET['renew']) && $_GET['renew'];
51
        $sessionRenewId = $sessionTicket ? $sessionTicket['renewId'] : null;
52
53
        $query = [];
54
55
        if ($sessionRenewId && $forceAuthn) {
56
            $query['renewId'] = $sessionRenewId;
57
        }
58
59
        if (isset($_REQUEST['service'])) {
60
            $query['service'] = $_REQUEST['service'];
61
        }
62
63
        if (isset($_REQUEST['TARGET'])) {
64
            $query['TARGET'] = $_REQUEST['TARGET'];
65
        }
66
67
        if (isset($_REQUEST['method'])) {
68
            $query['method'] = $_REQUEST['method'];
69
        }
70
71
        if (isset($_REQUEST['renew'])) {
72
            $query['renew'] = $_REQUEST['renew'];
73
        }
74
75
        if (isset($_REQUEST['gateway'])) {
76
            $query['gateway'] = $_REQUEST['gateway'];
77
        }
78
79
        if (\array_key_exists('language', $_GET)) {
80
            $query['language'] = \is_string($_GET['language']) ? $_GET['language'] : null;
81
        }
82
83
        if (isset($_REQUEST['debugMode'])) {
84
            $query['debugMode'] = $_REQUEST['debugMode'];
85
        }
86
87
        return $query;
88
    }
89
90
    /**
91
     * @param   Request  $request
92
     *
93
     * @return array
94
     */
95
    public function getRequestParams(Request $request): array
96
    {
97
        $params = [];
98
        if ($request->isMethod('GET')) {
99
            $params = $request->query->all();
100
        } elseif ($request->isMethod('POST')) {
101
            $params = $request->request->all();
102
        }
103
104
        return $params;
105
    }
106
}
107