Completed
Push — master ( 44676f...b7bc18 )
by Jens
13:18
created

DefaultCorrelationIdProvider::of()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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