Completed
Push — master ( 6b5beb...afd247 )
by Freek
01:16
created

SearchableAttribute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 44
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 4 1
A createExact() 0 4 1
A createMany() 0 8 1
A getAttribute() 0 4 1
A isPartial() 0 4 1
1
<?php
2
3
namespace Spatie\Searchable;
4
5
class SearchableAttribute
6
{
7
    /** @var string */
8
    protected $attribute;
9
10
    /** @var bool */
11
    protected $partial;
12
13
    public function __construct(string $attribute, bool $partial = true)
14
    {
15
        $this->attribute = $attribute;
16
17
        $this->partial = $partial;
18
    }
19
20
    public static function create(string $attribute, bool $partial = true): self
21
    {
22
        return new self($attribute, $partial);
23
    }
24
25
    public static function createExact(string $attribute): self
26
    {
27
        return static::create($attribute, false);
28
    }
29
30
    public static function createMany(array $attributes): array
31
    {
32
        return collect($attributes)
33
            ->map(function ($attribute) {
34
                return new self($attribute);
35
            })
36
            ->toArray();
37
    }
38
39
    public function getAttribute(): string
40
    {
41
        return $this->attribute;
42
    }
43
44
    public function isPartial(): bool
45
    {
46
        return $this->partial;
47
    }
48
}
49