Failed Conditions
Pull Request — main (#3585)
by Rafael
43:10
created

UrlHelper::setPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.2098
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace ApacheSolrForTypo3\Solr\System\Url;
17
18
use InvalidArgumentException;
19
use TYPO3\CMS\Core\Http\Uri;
20
21
/**
22
 * Class UrlHelper
23
 *
24
 * @author Timo Hund <[email protected]>
25
 */
26
class UrlHelper extends Uri
27
{
28
    /**
29
     * Remove a given parameter from the query and create a new instance.
30
     */
31
    public function withoutQueryParameter(string $parameterName): UrlHelper
32 3
    {
33
        parse_str($this->query, $parameters);
34 3
        if (isset($parameters[$parameterName])) {
35 3
            unset($parameters[$parameterName]);
36
        }
37
        $query = '';
38
        if (!empty($parameters)) {
39
            $query = http_build_query($parameters);
40
        }
41
        $query = $this->sanitizeQuery($query);
42
        $clonedObject = clone $this;
43
        $clonedObject->query = $query;
44
        return $clonedObject;
45
    }
46
47
    /**
48
     * Add a given parameter with value to the query and create a new instance.
49
     */
50
    public function withQueryParameter(string $parameterName, $value): UrlHelper
51
    {
52
        parse_str($this->query, $parameters);
53
        $parameters[$parameterName] = $value;
54
        $query = '';
55
        if (!empty($parameters)) {
56 2
            $query = http_build_query($parameters);
57
        }
58 2
        $query = $this->sanitizeQuery($query);
59 2
        $clonedObject = clone $this;
60
        $clonedObject->query = $query;
61
        return $clonedObject;
62
    }
63
64
}
65