Passed
Push — main ( 7e82e7...91ee3f )
by Michael
03:29
created

Uuid   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 51
ccs 8
cts 10
cp 0.8
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A uuid() 0 3 1
A value() 0 3 1
A __construct() 0 4 1
A toArray() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\ValueObjects\Collection\Complex;
6
7
use MichaelRubel\ValueObjects\ValueObject;
8
9
/**
10
 * @method static static make(string $uuid, string $name = null)
11
 */
12
class Uuid extends ValueObject
13
{
14
    /**
15
     * Create a new instance of the value object.
16
     *
17
     * @param  string|null  $uuid
18
     * @param  string|null  $name
19
     */
20 10
    public function __construct(
21
        protected ?string $uuid,
22
        protected ?string $name = null,
23
    ) {
24
        //
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function uuid(): string
31
    {
32
        return $this->value();
33
    }
34
35
    /**
36
     * @return string
37
     */
38 2
    public function name(): string
39
    {
40 2
        return (string) $this->name;
41
    }
42
43
    /**
44
     * Get the object value.
45
     *
46
     * @return string
47
     */
48 8
    public function value(): string
49
    {
50 8
        return (string) $this->uuid;
51
    }
52
53
    /**
54
     * Get an array representation of the value object.
55
     *
56
     * @return array
57
     */
58 1
    public function toArray(): array
59
    {
60
        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...
61 1
            'name'  => $this->name(),
62 1
            'value' => $this->value(),
63
        ];
64
    }
65
}
66