Completed
Push — master ( 7f5b14...1214f3 )
by Brian
03:58 queued 10s
created

Uuid   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 40.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 24
c 1
b 0
f 0
dl 0
loc 57
ccs 9
cts 22
cp 0.4091
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 22 6
A validate() 0 12 3
1
<?php
2
3
namespace Bmatovu\Uuid;
4
5
use Ramsey\Uuid\Uuid as RamseyUuid;
6
use Ramsey\Uuid\UuidInterface;
7
8
class Uuid
9
{
10
    /**
11
     * Generate UUID by version.
12
     *
13
     * @param int                               $version UUID Version
14
     * @param string|\Ramsey\Uuid\UuidInterface $ns The UUID namespace in which to create the named UUID
15
     * @param string                            $name The name to create a UUID for
16
     *
17
     * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException
18
     *
19
     * @return \Ramsey\Uuid\UuidInterface UUID
20
     */
21 3
    public static function generate(int $version = 4, $ns = null, string $name = null): UuidInterface
22
    {
23 3
        $ns = $ns ? $ns : RamseyUuid::NAMESPACE_DNS;
24
25 3
        $name = $name ? $name : php_uname('n');
26
27
        switch ($version) {
28 3
            case 1:
29
                $uuid = RamseyUuid::uuid1();
30
            break;
31 3
            case 3:
32
                $uuid = RamseyUuid::uuid3($ns, $name);
33
            break;
34 3
            case 5:
35
                $uuid = RamseyUuid::uuid5($ns, $name);
36
            break;
37
            default:
38 3
                $uuid = RamseyUuid::uuid4();
39 3
            break;
40
        }
41
42 3
        return $uuid;
43
    }
44
45
    /**
46
     * Validate UUID plus version.
47
     *
48
     * @param  string   $uuid
49
     * @param  int|null $version UUID Version
50
     *
51
     * @return bool True for valid.
52
     */
53
    public static function validate(string $uuid, int $version = null)
0 ignored issues
show
Unused Code introduced by
The parameter $uuid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
    public static function validate(/** @scrutinizer ignore-unused */ string $uuid, int $version = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        if ($version === null) {
56
            return RamseyUuid::isValid($value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value seems to be never defined.
Loading history...
57
        }
58
59
        try {
60
            $uuid = RamseyUuid::fromString($value);
61
62
            return $uuid->getVersion() === $version;
0 ignored issues
show
Deprecated Code introduced by
The function Ramsey\Uuid\DeprecatedUuidInterface::getVersion() has been deprecated: Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getVersion()}. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

62
            return /** @scrutinizer ignore-deprecated */ $uuid->getVersion() === $version;

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
63
        } catch (InvalidUuidStringException $e) {
0 ignored issues
show
Bug introduced by
The type Bmatovu\Uuid\InvalidUuidStringException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
            return false;
65
        }
66
    }
67
}
68