Passed
Push — master ( da0795...78880b )
by Jens
14:45 queued 18s
created

UserAgentProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 11
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserAgent() 0 3 1
A __construct() 0 12 4
A getAdapterInfo() 0 3 1
1
<?php
2
3
namespace Commercetools\Core\Client;
4
5
use Commercetools\Core\Client;
6
use GuzzleHttp\Client as HttpClient;
7
8
class UserAgentProvider
9
{
10
    private $userAgent;
11
12
    /**
13
     * UserAgentProvider constructor.
14
     * @param string $userAgent
15
     */
16 5
    public function __construct($userAgent = null)
17
    {
18 5
        if (is_null($userAgent)) {
19 5
            $userAgent = 'commercetools-php-sdk/' . Client::VERSION;
20
21 5
            $userAgent .= ' (' . $this->getAdapterInfo();
22 5
            if (extension_loaded('curl') && function_exists('curl_version')) {
23 5
                $userAgent .= '; curl/' . \curl_version()['version'];
24
            }
25 5
            $userAgent .= ') PHP/' . PHP_VERSION;
26
        }
27 5
        $this->userAgent = $userAgent;
28 5
    }
29
30
    /**
31
     * @return string
32
     */
33 5
    public function getUserAgent()
34
    {
35 5
        return $this->userAgent;
36
    }
37
38 5
    private function getAdapterInfo()
39
    {
40 5
        return 'GuzzleHttp/' . HttpClient::VERSION;
41
    }
42
}
43