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

RedirectResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 34.38 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 0
dl 11
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUrl() 11 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}