UUID   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 12.7 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 4
dl 8
loc 63
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNative() 0 7 1
A generateAsString() 0 7 1
A sameValueAs() 8 8 2
A __construct() 0 16 3

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
namespace EventStore\ValueObjects\Identity;
3
4
use EventStore\ValueObjects\Exception\InvalidNativeArgumentException;
5
use EventStore\ValueObjects\StringLiteral\StringLiteral;
6
use EventStore\ValueObjects\Util\Util;
7
use EventStore\ValueObjects\ValueObjectInterface;
8
use Ramsey\Uuid\Uuid as BaseUuid;
9
10
class UUID extends StringLiteral
11
{
12
    /** @var BaseUuid */
13
    protected $value;
14
15
    /**
16
     * @param  string                                                 $uuid
0 ignored issues
show
Bug introduced by
There is no parameter named $uuid. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
17
     * @return UUID
18
     * @throws \ValueObjects\Exception\InvalidNativeArgumentException
19
     */
20 1
    public static function fromNative()
21
    {
22 1
        $uuid_str = \func_get_arg(0);
23 1
        $uuid     = new static($uuid_str);
24
25 1
        return $uuid;
26
    }
27
28
    /**
29
     * Generate a new UUID string
30
     *
31
     * @return string
32
     */
33 1
    public static function generateAsString()
34
    {
35 1
        $uuid       = new static();
36 1
        $uuidString = $uuid->toNative();
37
38 1
        return $uuidString;
39
    }
40
41 28
    public function __construct($value = null)
42
    {
43 28
        $uuid_str = BaseUuid::uuid4();
44
45 28
        if (null !== $value) {
46 2
            $pattern = '/'.BaseUuid::VALID_PATTERN.'/';
47
48 2
            if (! \preg_match($pattern, $value)) {
49 1
                throw new InvalidNativeArgumentException($value, array('UUID string'));
50
            }
51
52 1
            $uuid_str = $value;
53
        }
54
55 27
        $this->value = \strval($uuid_str);
0 ignored issues
show
Documentation Bug introduced by
It seems like \strval($uuid_str) of type string is incompatible with the declared type object<Ramsey\Uuid\Uuid> of property $value.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56 27
    }
57
58
    /**
59
     * Tells whether two UUID are equal by comparing their values
60
     *
61
     * @param  UUID $uuid
62
     * @return bool
63
     */
64 2 View Code Duplication
    public function sameValueAs(ValueObjectInterface $uuid)
0 ignored issues
show
Duplication introduced by
This method 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...
65
    {
66 2
        if (false === Util::classEquals($this, $uuid)) {
67 1
            return false;
68
        }
69
70 2
        return $this->toNative() === $uuid->toNative();
71
    }
72
}
73