Passed
Push — main ( ec6948...9b9c4a )
by Michael
04:01
created

Uuid::value()   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 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\ValueObjects\Complex;
6
7
use Illuminate\Contracts\Support\Arrayable;
8
use Illuminate\Support\Traits\Conditionable;
9
use Illuminate\Support\Traits\Macroable;
10
use MichaelRubel\ValueObjects\ValueObject;
11
12
/**
13
 * @method make(string $uuid, string $name)
14
 */
15
class Uuid extends ValueObject implements Arrayable
16
{
17
    use Macroable, Conditionable;
18
19
    /**
20
     * @param  string|null  $uuid
21
     * @param  string|null  $name
22
     */
23 8
    public function __construct(
24
        protected ?string $uuid,
25
        protected ?string $name = null,
26
    ) {
27
        //
28
    }
29
30
    /**
31
     * @return string
32
     */
33 2
    public function name(): string
34
    {
35 2
        return (string) $this->name;
36
    }
37
38
    /**
39
     * @return string
40
     */
41 6
    public function value(): string
42
    {
43 6
        return (string) $this->uuid;
44
    }
45
46
    /**
47
     * @return array
48
     */
49 1
    public function toArray(): array
50
    {
51
        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...
52 1
            'name'  => $this->name(),
53 1
            'value' => $this->value(),
54
        ];
55
    }
56
57
    /**
58
     * @return string
59
     */
60 1
    public function __toString(): string
61
    {
62 1
        return $this->value();
63
    }
64
}
65