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

UserAgentProvider::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 4
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