Completed
Push — master ( fcb692...e69fbf )
by Freek
37:28 queued 36:25
created

SlugOptions   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 8
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 8
cbo 0
dl 0
loc 96
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Sluggable;
4
5
class SlugOptions
6
{
7
    /** @var array|callable */
8
    public $generateSlugFrom;
9
10
    public string $slugField;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
11
12
    public bool $generateUniqueSlugs = true;
13
14
    public int $maximumLength = 250;
15
16
    public bool $generateSlugsOnCreate = true;
17
18
    public bool $generateSlugsOnUpdate = true;
19
20
    public string $slugSeparator = '-';
21
22
    public string $slugLanguage = 'en';
23
24
    public static function create(): self
25
    {
26
        return new static();
27
    }
28
29
    /**
30
     * @param string|array|callable $fieldName
31
     *
32
     * @return \Spatie\Sluggable\SlugOptions
33
     */
34
    public function generateSlugsFrom($fieldName): self
35
    {
36
        if (is_string($fieldName)) {
37
            $fieldName = [$fieldName];
38
        }
39
40
        $this->generateSlugFrom = $fieldName;
41
42
        return $this;
43
    }
44
45
    public function saveSlugsTo(string $fieldName): self
46
    {
47
        $this->slugField = $fieldName;
48
49
        return $this;
50
    }
51
52
    public function allowDuplicateSlugs(): self
53
    {
54
        $this->generateUniqueSlugs = false;
55
56
        return $this;
57
    }
58
59
    public function slugsShouldBeNoLongerThan(int $maximumLength): self
60
    {
61
        $this->maximumLength = $maximumLength;
62
63
        return $this;
64
    }
65
66
    public function doNotGenerateSlugsOnCreate(): self
67
    {
68
        $this->generateSlugsOnCreate = false;
69
70
        return $this;
71
    }
72
73
    public function doNotGenerateSlugsOnUpdate(): self
74
    {
75
        $this->generateSlugsOnUpdate = false;
76
77
        return $this;
78
    }
79
80
    public function usingSeparator(string $separator): self
81
    {
82
        $this->slugSeparator = $separator;
83
84
        return $this;
85
    }
86
87
    public function usingLanguage(string $language): self
88
    {
89
        $this->slugLanguage = $language;
90
91
        return $this;
92
    }
93
}
94