Completed
Push — master ( 312098...b95ba9 )
by Nikolas
40:06
created

RedirectResult::getUrl()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 3
eloc 8
nc 2
nop 0
1
<?php
2
namespace rtens\domin\execution;
3
4
class RedirectResult implements ExecutionResult {
5
6
    /** @var string */
7
    private $target;
8
9
    /** @var array|\string[] */
10
    private $parameters;
11
12
    /**
13
     * @param string $target
14
     * @param string[] $parameters
15
     */
16
    public function __construct($target, array $parameters = []) {
17
        $this->target = $target;
18
        $this->parameters = $parameters;
19
    }
20
21
    /**
22
     * @return string
23
     */
24 View Code Duplication
    public function getUrl() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
        $url = $this->target;
26
        if ($this->parameters) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->parameters of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
27
            $keyValues = [];
28
            foreach ($this->parameters as $key => $value) {
29
                $keyValues[] = urlencode($key) . '=' . urlencode($value);
30
            }
31
            $url .= '?' . implode('&', $keyValues);
32
        }
33
        return $url;
34
    }
35
}