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

URLHelper::addParam()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 12
nop 3
dl 0
loc 18
ccs 0
cts 14
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
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