Passed
Push — main ( b3cf5c...f07e9b )
by Yaroslav
18:34
created

LayoutsCollection   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 17
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 3 1
A whereName() 0 5 1
1
<?php
2
3
namespace NovaFlexibleContent\Layouts\Collections;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Collection as BaseCollection;
7
use NovaFlexibleContent\Layouts\Layout;
8
9
/**
10
 * @extends  \Illuminate\Support\Collection<int, \NovaFlexibleContent\Layouts\Layout>
11
 */
12
class LayoutsCollection extends BaseCollection
13
{
14
    /**
15
     * Find a layout based on its name
16
     *
17
     * @return \NovaFlexibleContent\Layouts\Layout|mixed
18
     */
19 14
    public function find(string $name, mixed $default = null): mixed
20
    {
21 14
        return $this->first(fn (Layout $layout) => $layout->name() === $name, $default);
22
    }
23
24 1
    public function whereName(string|array $names): static
25
    {
26 1
        $names = array_filter(array_unique(Arr::wrap($names)));
27
28 1
        return $this->filter(fn (Layout $layout) => in_array($layout->name(), $names));
29
    }
30
31
}
32