Passed
Push — main ( 01d627...8c0949 )
by Michael
03:55
created

Uuid   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 6
eloc 9
c 6
b 0
f 1
dl 0
loc 56
ccs 10
cts 12
cp 0.8333
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A uuid() 0 3 1
A __toString() 0 3 1
A __construct() 0 4 1
A name() 0 3 1
A toArray() 0 5 1
A value() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\ValueObjects\Complex;
6
7
use Illuminate\Support\Traits\Conditionable;
8
use Illuminate\Support\Traits\Macroable;
9
use MichaelRubel\ValueObjects\ValueObject;
10
11
/**
12
 * @method static static make(string $uuid, string $name)
13
 */
14
class Uuid extends ValueObject
15
{
16
    use Macroable, Conditionable;
17
18
    /**
19
     * @param  string|null  $uuid
20
     * @param  string|null  $name
21
     */
22 8
    public function __construct(
23
        protected ?string $uuid,
24
        protected ?string $name = null,
25
    ) {
26
        //
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function uuid(): string
33
    {
34
        return $this->value();
35
    }
36
37
    /**
38
     * @return string
39
     */
40 2
    public function name(): string
41
    {
42 2
        return (string) $this->name;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 6
    public function value(): string
49
    {
50 6
        return (string) $this->uuid;
51
    }
52
53
    /**
54
     * @return array
55
     */
56 1
    public function toArray(): array
57
    {
58
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('name' => $...lue' => $this->value()) returns the type array<string,string> which is incompatible with the return type mandated by Illuminate\Contracts\Support\Arrayable::toArray() of Illuminate\Contracts\Support\TValue[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
59 1
            'name'  => $this->name(),
60 1
            'value' => $this->value(),
61
        ];
62
    }
63
64
    /**
65
     * @return string
66
     */
67 1
    public function __toString(): string
68
    {
69 1
        return $this->value();
70
    }
71
}
72