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

ClassString::classExists()   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 0
Metric Value
cc 1
eloc 1
c 1
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|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