Completed
Pull Request — develop (#333)
by Jens
14:58
created

DefaultCorrelationIdProvider::getCorrelationId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Helper;
7
8
use Ramsey\Uuid\Uuid;
9
10
class DefaultCorrelationIdProvider implements CorrelationIdProvider
11
{
12
    private $projectKey;
13
14 39
    public function __construct($projectKey = null)
15
    {
16 39
        $projectKey = !empty($projectKey) ? $projectKey : 'php';
17 39
        $this->projectKey = $projectKey;
18 39
    }
19
20 475
    public function getCorrelationId()
21
    {
22 475
        return sprintf('%s/%s', $this->projectKey, Uuid::uuid4()->toString());
23
    }
24
25
    /**
26
     * Returns an instance if ramsay\uuid package is installed
27
     * @param string $projectKey
28
     * @return DefaultCorrelationIdProvider|null
29
     */
30 39
    public static function of($projectKey)
31
    {
32 39
        if (class_exists('\Ramsey\Uuid\Uuid')) {
33 39
            return new DefaultCorrelationIdProvider($projectKey);
34
        }
35
        return null;
36
    }
37
}
38