Passed
Push — master ( ed9e54...fafb16 )
by Timo
02:50
created

RequestHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHostAndPath() 0 7 1
A _getMethodAndParams() 0 3 1
A getStorageKey() 0 11 2
1
<?php
2
3
namespace hamburgscleanest\GuzzleAdvancedThrottle\Cache\Helpers;
4
5
use Psr\Http\Message\RequestInterface;
6
7
/**
8
 * Class RequestHelper
9
 * @package hamburgscleanest\GuzzleAdvancedThrottle\Cache\Helpers
10
 */
11
class RequestHelper
12
{
13
14
    /**
15
     * @param RequestInterface $request
16
     * @return array
17
     */
18 11
    public static function getHostAndPath(RequestInterface $request) : array
19
    {
20 11
        $uri = $request->getUri();
21
22
        return [
23 11
            $uri->getScheme() . '://' . $uri->getHost(),
24 11
            $uri->getPath()
25
        ];
26
    }
27
28
    /**
29
     * @param RequestInterface $request
30
     * @return string
31
     */
32 12
    public static function getStorageKey(RequestInterface $request) : string
33
    {
34 12
        $uri = $request->getUri();
35 12
        $method = $request->getMethod();
36
37 12
        if ($method !== 'GET')
38
        {
39 2
            return self::_getMethodAndParams($method, $request->getBody()->getContents());
40
        }
41
42 10
        return self::_getMethodAndParams($method, $uri->getQuery());
43
    }
44
45
    /**
46
     * @param string $method
47
     * @param string $params
48
     * @return string
49
     */
50 12
    private static function _getMethodAndParams(string $method, string $params) : string
51
    {
52 12
        return $method . '_' . $params;
53
    }
54
}