ServiceNameExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A extract() 0 12 3
1
<?php
2
namespace Ackintosh\Ganesha\GuzzleMiddleware;
3
4
use Psr\Http\Message\RequestInterface;
5
6
class ServiceNameExtractor implements ServiceNameExtractorInterface
7
{
8
    /**
9
     * @var string
10
     */
11
    const OPTION_KEY = 'ganesha.service_name';
12
13
    /**
14
     * @var string
15
     */
16
    const HEADER_NAME = 'X-Ganesha-Service-Name';
17
18
    /**
19
     * @param RequestInterface $request
20
     * @param array $requestOptions
21
     * @return string
22
     */
23
    public function extract(RequestInterface $request, array $requestOptions)
24
    {
25
        if (array_key_exists(self::OPTION_KEY, $requestOptions)) {
26
            return $requestOptions[self::OPTION_KEY];
27
        }
28
29
        $header = $request->getHeader(self::HEADER_NAME);
30
        if (count($header)) {
31
            return $header[0];
32
        }
33
34
        return $request->getUri()->getHost();
35
    }
36
}
37