Passed
Push — develop ( 38ffd9...9f7101 )
by Jens
31:57 queued 05:22
created

UserAgentProvider::getAdapterInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 10
c 1
b 0
f 1
cc 2
nc 2
nop 0
crap 2.032
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 27
    public function __construct($userAgent = null)
17
    {
18 27
        if (is_null($userAgent)) {
19 27
            $userAgent = 'commercetools-php-sdk/' . Client::VERSION;
20
21 27
            $userAgent .= ' (' . $this->getAdapterInfo();
22 27
            if (extension_loaded('curl') && function_exists('curl_version')) {
23 27
                $userAgent .= '; curl/' . \curl_version()['version'];
24
            }
25 27
            $userAgent .= ') PHP/' . PHP_VERSION;
26
        }
27 27
        $this->userAgent = $userAgent;
28 27
    }
29
30
    /**
31
     * @return string
32
     */
33 27
    public function getUserAgent()
34
    {
35 27
        return $this->userAgent;
36
    }
37
38 27
    private function getAdapterInfo()
39
    {
40 27
        if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
41 27
            $clientVersion = (string) constant(HttpClient::class . '::MAJOR_VERSION');
42
        } else {
43
            $clientVersion = (string) constant(HttpClient::class . '::VERSION');
44
        }
45 27
        return 'GuzzleHttp/' . $clientVersion;
46
    }
47
}
48