Passed
Push — main ( 01d627...8c0949 )
by Michael
03:55
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\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