SearchResultCollection::addResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\Searchable;
4
5
use Illuminate\Support\Collection;
6
7
class SearchResultCollection extends Collection
8
{
9
    public function addResults(string $type, Collection $results)
10
    {
11
        $results->each(function ($result) use ($type) {
12
            $this->items[] = $result->getSearchResult()->setType($type);
13
        });
14
15
        return $this;
16
    }
17
18
    public function groupByType(): Collection
19
    {
20
        return $this->groupBy(function (SearchResult $searchResult) {
21
            return $searchResult->type;
22
        });
23
    }
24
25
    public function aspect(string $aspectName): Collection
26
    {
27
        return $this->groupByType()->get($aspectName);
28
    }
29
}
30