Passed
Push — main ( 267d80...2eae33 )
by Michael
03:37
created

ClassString   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 62
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A classExists() 0 3 1
A __construct() 0 2 1
A interfaceExists() 0 3 1
A instantiate() 0 3 1
A instantiateWith() 0 3 1
A value() 0 3 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|null $string)
11
 * @method static static from(string|null $string)
12
 */
13
class ClassString extends ValueObject
14
{
15
    /**
16
     * Create a new instance of the value object.
17
     *
18
     * @param  string|null  $string
19
     */
20 16
    public function __construct(protected ?string $string)
21
    {
22
        //
23
    }
24
25
    /**
26
     * Determine if the class exists for this class string.
27
     *
28
     * @return bool
29
     */
30 5
    public function classExists(): bool
31
    {
32 5
        return class_exists($this->value());
33
    }
34
35
    /**
36
     * Determine if the interface exists for this class string.
37
     *
38
     * @return bool
39
     */
40 5
    public function interfaceExists(): bool
41
    {
42 5
        return interface_exists($this->value());
43
    }
44
45
    /**
46
     * Instantiate the class string if possible.
47
     *
48
     * @return object
49
     */
50 1
    public function instantiate(): object
51
    {
52 1
        return app($this->value());
53
    }
54
55
    /**
56
     * Instantiate the class string if possible.
57
     *
58
     * @param  array  $parameters
59
     *
60
     * @return object
61
     */
62 1
    public function instantiateWith(array $parameters = []): object
63
    {
64 1
        return app($this->value(), $parameters);
65
    }
66
67
    /**
68
     * Get the object value.
69
     *
70
     * @return string
71
     */
72 13
    public function value(): string
73
    {
74 13
        return (string) $this->string;
75
    }
76
}
77