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

DefaultCorrelationIdProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
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
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