Passed
Push — feature/second-release ( 8aa292...512416 )
by Andrea Marco
03:19
created

CasesCollection::dd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LaravelEnum;
6
7
use Cerbero\Enum\CasesCollection as BaseCasesCollection;
8
use Illuminate\Contracts\Support\Arrayable;
9
use Illuminate\Contracts\Support\Jsonable;
10
use Illuminate\Support\Traits\Conditionable;
11
use Illuminate\Support\Traits\Macroable;
12
use Illuminate\Support\Traits\Tappable;
13
use JsonSerializable;
14
use Stringable;
15
16
/**
17
 * The collection of enum cases.
18
 *
19
 * @template TKey of array-key
20
 * @template TValue
21
 *
22
 * @extends BaseCasesCollection<TKey, TValue>
23
 */
24
class CasesCollection extends BaseCasesCollection implements Arrayable, Jsonable, JsonSerializable, Stringable
25
{
26
    use Conditionable;
27
    use Macroable;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Support\Traits\Macroable requires the property $name which is not provided by Cerbero\LaravelEnum\CasesCollection.
Loading history...
28
    use Tappable;
29
30
    /**
31
     * Turn the collection into a string.
32
     */
33 1
    public function __toString(): string
34
    {
35 1
        return $this->toJson();
36
    }
37
38
    /**
39
     * Turn the collection into a JSON.
40
     *
41
     * @param int $options
42
     */
43 2
    public function toJson($options = 0): string|false
44
    {
45 2
        return json_encode($this->toArray(), $options);
46
    }
47
48
    /**
49
     * Turn the collection into a JSON serializable array.
50
     *
51
     * @return array<TKey, mixed>
52
     */
53 1
    public function jsonSerialize(): array
54
    {
55 1
        return $this->toArray();
56
    }
57
58
    /**
59
     * Dump the cases and end the script.
60
     *
61
     * @codeCoverageIgnore
62
     */
63
    public function dd(): never
64
    {
65
        $this->dump();
66
67
        exit(1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
68
    }
69
70
    /**
71
     * Dump the cases.
72
     */
73 1
    public function dump(): static
74
    {
75 1
        dump($this->cases);
76
77 1
        return $this;
78
    }
79
}
80