Completed
Push — master ( 2510ed...09ec49 )
by Shawn
03:37
created

DebugMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pragmaHeaders() 0 3 1
A __invoke() 0 3 1
1
<?php
2
/**
3
 * This file is part of the RHDC Akamai middleware package.
4
 *
5
 * (c) Shawn Iwinski <[email protected]>
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
namespace Rhdc\Akamai\Middleware\Request;
11
12
use Psr\Http\Message\RequestInterface;
13
14
class DebugMiddleware implements MiddlewareInterface
15
{
16
    /**
17
     * Akamai debug pragma header values
18
     *
19
     * @var string[]
20
     */
21
    protected static $pragmaHeaders = array(
22
        'akamai-x-cache-on',
23
        'akamai-x-cache-remote-on',
24
        'akamai-x-check-cacheable',
25
        'akamai-x-feo-trace',
26
        'akamai-x-get-cache-key',
27
        'akamai-x-get-client-ip',
28
        'akamai-x-get-extracted-values',
29
        'akamai-x-get-nonces',
30
        'akamai-x-get-request-id',
31
        'akamai-x-get-ssl-client-session-id',
32
        'akamai-x-get-true-cache-key',
33
        'akamai-x-serial-no',
34
    );
35
36
    /**
37
     * Returns array of Akamai debug pragma header values
38
     *
39
     * @return string[]
40
     */
41 2
    public static function pragmaHeaders()
42
    {
43 2
        return static::$pragmaHeaders;
44
    }
45
46
    /**
47
     * Returns a new modified request instance with Akamai debug pragma headers
48
     *
49
     * - If the original request does not already have a pragma header, it will
50
     *   be added with the Akamai debug values
51
     * - If the original request already has a pragma header, the Akamai debug
52
     *   values will be combined with the existing value(s)
53
     *
54
     * @param RequestInterface $request Original request
55
     *
56
     * @return RequestInterface New modified request instance with Akamai debug pragma headers
57
     */
58 2
    public function __invoke(RequestInterface $request)
59
    {
60 2
        return $request->withAddedHeader('Pragma', static::$pragmaHeaders);
61
    }
62
}
63