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

UrlTrait::getRequestParams()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\casserver\Controller\Traits;
6
7
use SimpleSAML\Module\casserver\Cas\ServiceValidator;
8
use SimpleSAML\Module\casserver\Cas\TicketValidator;
9
use Symfony\Component\HttpFoundation\Request;
10
11
trait UrlTrait
12
{
13
    /**
14
     * @deprecated
15
     * @see ServiceValidator
16
     * @param string $service
17
     * @param array $legal_service_urls
18
     * @return bool
19
     */
20
    public function checkServiceURL(string $service, array $legal_service_urls): bool
21
    {
22
        //delegate to ServiceValidator until all references to this can be cleaned up
23
        $config = Configuration::loadFromArray(['legal_service_urls' => $legal_service_urls]);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Module\casser...er\Traits\Configuration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
        $serviceValidator = new ServiceValidator($config);
25
        return $serviceValidator->checkServiceURL($service) !== null;
26
    }
27
28
29
    /**
30
     * @param string $parameter
31
     * @return string
32
     */
33
    public function sanitize(string $parameter): string
34
    {
35
        return TicketValidator::sanitize($parameter);
36
    }
37
38
39
    /**
40
     * Parse the query Parameters from $_GET global and return them in an array.
41
     *
42
     * @param   array|null  $sessionTicket
43
     * @param   Request     $request
44
     *
45
     * @return array
46
     */
47
    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

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