Passed
Push — develop ( 9b8c4e...79e7ae )
by Andrea Marco
03:34 queued 14s
created

CasesCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toJson() 0 3 1
A dd() 0 5 1
A of() 0 3 1
A dump() 0 5 1
A castUsing() 0 4 1
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\Database\Eloquent\Castable;
9
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
10
use Illuminate\Contracts\Support\Arrayable;
11
use Illuminate\Contracts\Support\Jsonable;
12
use Illuminate\Support\Traits\Conditionable;
13
use Illuminate\Support\Traits\Macroable;
14
use Illuminate\Support\Traits\Tappable;
15
16
/**
17
 * The collection of enum cases.
18
 *
19
 * @template TEnum of \UnitEnum
20
 *
21
 * @extends BaseCasesCollection<TEnum>
22
 * @implements Arrayable<array-key, TEnum>
23
 */
24
class CasesCollection extends BaseCasesCollection implements Arrayable, Castable, Jsonable
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
     * Retrieve the caster to cast the collection.
32
     *
33
     * @param list<string> $arguments
0 ignored issues
show
Bug introduced by
The type Cerbero\LaravelEnum\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
     * @return CasesCollectionCast<TEnum>
35
     */
36 19
    public static function castUsing(array $arguments): CastsAttributes
37
    {
38
        /** @var CasesCollectionCast<TEnum> */
39 19
        return new CasesCollectionCast($arguments[0] ?? '');
40
    }
41
42
    /**
43
     * Retrieve the cast for the given enum.
44
     *
45
     * @param class-string<TEnum> $enum
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<TEnum> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<TEnum>.
Loading history...
46
     */
47 1
    public static function of(string $enum): string
48
    {
49 1
        return static::class . ':' . $enum;
50
    }
51
52
    /**
53
     * Turn the collection into a JSON.
54
     *
55
     * @param int $options
56
     */
57 3
    public function toJson($options = 0): string|false
58
    {
59 3
        return json_encode($this->jsonSerialize(), $options);
60
    }
61
62
    /**
63
     * Dump the cases and end the script.
64
     *
65
     * @codeCoverageIgnore
66
     */
67
    public function dd(): never
68
    {
69
        $this->dump();
70
71
        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...
72
    }
73
74
    /**
75
     * Dump the cases.
76
     */
77 1
    public function dump(): static
78
    {
79 1
        dump($this->cases);
80
81 1
        return $this;
82
    }
83
}
84