SearchResultCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addResults() 0 8 1
A groupByType() 0 6 1
A aspect() 0 4 1
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