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

DefaultCorrelationIdProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 28
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getCorrelationId() 0 4 1
A of() 0 7 2
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