| Conditions | 9 |
| Paths | 128 |
| Total Lines | 34 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 24 |
| CRAP Score | 9 |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 27 | 5 | protected static function parseOptions($options) |
|
| 28 | { |
||
| 29 | $default = [ |
||
| 30 | 5 | 'scheme' => '', |
|
| 31 | 5 | 'host' => '', |
|
| 32 | 5 | 'port' => '', |
|
| 33 | 5 | 'path' => '', |
|
| 34 | 5 | 'query' => [], |
|
| 35 | 5 | 'fragment' => '', |
|
| 36 | 5 | ]; |
|
| 37 | |||
| 38 | 5 | $optArr = (!is_array($options)) ? parse_url($options) : $options; |
|
| 39 | 5 | $optArr = array_merge($default, $optArr); |
|
| 40 | |||
| 41 | 5 | if (isset($optArr['secure'])) { |
|
| 42 | 3 | $scheme = ((bool) $optArr['secure']) ? 'wss' : 'ws'; |
|
| 43 | |||
| 44 | 3 | } else { |
|
| 45 | 4 | $scheme = (in_array($optArr['scheme'], ['wss', 'https'])) ? 'wss' : 'ws'; |
|
| 46 | } |
||
| 47 | |||
| 48 | 5 | $query = $optArr['query']; |
|
| 49 | 5 | if (!is_array($query)) { |
|
| 50 | 1 | parse_str($optArr['query'], $query); |
|
| 51 | 1 | } |
|
| 52 | |||
| 53 | 5 | $host = trim($optArr['host'], "/"); |
|
| 54 | 5 | $port = !empty($optArr['port']) ? ":".$optArr['port'] : ''; |
|
| 55 | 5 | $path = trim($optArr['path'], "/"); |
|
| 56 | 5 | $path = !empty($path) ? $path."/" : ''; |
|
| 57 | 5 | $query = count($query) ? '?'.http_build_query($query) : ''; |
|
| 58 | |||
| 59 | 5 | return sprintf("%s://%s%s/%s%s", $scheme, $host, $port, $path, $query); |
|
| 60 | } |
||
| 61 | } |
||
| 62 |