Completed
Push — trunk ( 0e7a2e...6a6c5e )
by SuperNova.WS
07:28
created

URLHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B addParam() 0 18 5
1
<?php
2
/**
3
 * Created by Gorlum 25.11.2017 22:10
4
 */
5
6
namespace General\Helpers;
7
8
9
class URLHelper {
10
11
  public static function addParam($url, $param, $value = '') {
12
    list($urlItself, $strParams) = explode('?', $url);
13
14
    $paramList = explode('&', $strParams);
15
    foreach ($paramList as $key => $val) {
16
      list($thisName, $thisParam) = explode('=', $val);
17
      if ($thisName == $param) {
18
        unset($paramList[$key]);
19
      }
20
    }
21
22
    if(!empty($paramList)) {
23
      $strParams = implode('&', $paramList);
24
    }
25
26
    $url = $urlItself . '?' . $strParams;
27
28
    return $url . (strpos($url, '?') === false ? '?' : '&') . $param . '=' . $value;
29
  }
30
31
}
32