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

Uuid::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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