Passed
Push — main ( 6175ee...752a2b )
by Michael
03:40
created

ClassString::__toString()   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 Illuminate\Support\Traits\Tappable;
10
use MichaelRubel\ValueObjects\ValueObject;
11
12
class ClassString implements ValueObject
13
{
14
    use Macroable, Conditionable, Tappable;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Support\Traits\Macroable requires the property $name which is not provided by MichaelRubel\ValueObjects\Complex\ClassString.
Loading history...
15
16
    /**
17
     * Create a new value object instance.
18
     *
19
     * @param string|null $classString
20
     */
21 10
    final public function __construct(public ?string $classString)
22
    {
23
        //
24
    }
25
26
    /**
27
     * Return a new instance of value object.
28
     *
29
     * @param string|null $classString
30
     *
31
     * @return static
32
     */
33 3
    public static function make(?string $classString): static
34
    {
35 3
        return new static($classString);
36
    }
37
38
    /**
39
     * @return bool
40
     */
41 5
    public function isClassExists(): bool
42
    {
43 5
        return class_exists($this->classString);
0 ignored issues
show
Bug introduced by
It seems like $this->classString can also be of type null; however, parameter $class of class_exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        return class_exists(/** @scrutinizer ignore-type */ $this->classString);
Loading history...
44
    }
45
46
    /**
47
     * @return bool
48
     */
49 4
    public function isInterfaceExists(): bool
50
    {
51 4
        return interface_exists($this->classString);
0 ignored issues
show
Bug introduced by
It seems like $this->classString can also be of type null; however, parameter $interface of interface_exists() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        return interface_exists(/** @scrutinizer ignore-type */ $this->classString);
Loading history...
52
    }
53
54
    /**
55
     * Get the last name.
56
     *
57
     * @return string
58
     */
59 4
    public function getClassString(): string
60
    {
61 4
        return str($this->classString)->value();
62
    }
63
64
    /**
65
     * Return the first UUID if cast to string.
66
     *
67
     * @return string
68
     */
69 2
    public function __toString(): string
70
    {
71 2
        return $this->getClassString();
72
    }
73
}
74