Completed
Push — master ( f80030...418223 )
by Alexandru
06:28
created

Uuid3Generator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 28
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 2
A generate() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Arki\RequestId library.
5
 *
6
 * (c) Alexandru Furculita <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.md.
10
 */
11
12
namespace Arki\RequestId\Generators;
13
14
use Ramsey\Uuid\UuidFactory;
15
use Ramsey\Uuid\UuidFactoryInterface;
16
17 View Code Duplication
final class Uuid3Generator implements RequestIdGenerator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    private $ns;
20
21
    private $name;
22
23
    private $factory;
24
25
    /**
26
     * @param UuidFactoryInterface $factory
27
     * @param string               $ns
28
     * @param string               $name
29
     */
30
    public function __construct($ns, $name, UuidFactoryInterface $factory = null)
31
    {
32
        $this->factory = $factory ?: new UuidFactory();
33
        $this->ns = $ns;
34
        $this->name = $name;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function generate()
41
    {
42
        return $this->factory->uuid3($this->ns, $this->name)->toString();
43
    }
44
}
45