Completed
Pull Request — master (#42)
by Chad
01:31
created

CacheHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCacheKey() 0 16 1
1
<?php
2
3
namespace TraderInteractive\Api;
4
5
abstract class CacheHelper
6
{
7
    /**
8
     * Returns a valid PSR-11 key.
9
     *
10
     * @param Request $request The request from which the key will be generated.
11
     *
12
     * @return string
13
     */
14
    public static function getCacheKey(Request $request) : string
15
    {
16
        $key = "{$request->getUrl()}|{$request->getBody()}";
17
        $map = [
18
            '{' => '_LBRACE_',
19
            '}'=> '_RBRACE_',
20
            '('=> '_LPAREN_',
21
            ')'=> '_RPAREN_',
22
            '/'=> '_FSLASH_',
23
            '\\'=> '_BSLASH_',
24
            '@'=> '_AT_',
25
            ':'=> '_COLON_',
26
        ];
27
28
        return str_replace(array_keys($map), $map, $key);
29
    }
30
}
31