UrlOptions::glueUrlWith()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Neurony\Url\Options;
4
5
use Exception;
6
7
class UrlOptions
8
{
9
    /**
10
     * The controller where the laravel router should dispatch the request.
11
     * This is used when a URI is accessed by a user.
12
     * The format of this property should be Full\Namespace\Of\Controller.
13
     *
14
     * @var string
15
     */
16
    private $routeController;
17
18
    /**
19
     * The controller where the laravel router should dispatch the request.
20
     * This is used when a URI is accessed by a user.
21
     * The format of this property should be simply the name of the method residing inside the $routeController.
22
     *
23
     * @var string
24
     */
25
    private $routeAction;
26
27
    /**
28
     * The field used to generate the url slug from.
29
     *
30
     * @var string|array|callable
31
     */
32
    private $fromField;
33
34
    /**
35
     * The field where to store the generated url slug.
36
     *
37
     * @var string
38
     */
39
    private $toField;
40
41
    /**
42
     * The prefix that should be prepended to the generated url slug.
43
     *
44
     * @var string|array|callable
45
     */
46
    private $urlPrefix;
47
48
    /**
49
     * The suffix that should be appended to the generated url slug.
50
     *
51
     * @var string|array|callable
52
     */
53
    private $urlSuffix;
54
55
    /**
56
     * The symbol that will be used to glue url segments together.
57
     *
58
     * @var string
59
     */
60
    private $urlGlue = '/';
61
62
    /**
63
     * Flag whether to update children urls on parent url save.
64
     *
65
     * @var bool
66
     */
67
    private $cascadeUpdate = true;
68
69
    /**
70
     * Get the value of a property of this class.
71
     *
72
     * @param $name
73
     * @return mixed
74
     * @throws Exception
75
     */
76 View Code Duplication
    public function __get($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        if (property_exists(static::class, $name)) {
79
            return $this->{$name};
80
        }
81
82
        throw new Exception(
83
            'The property "'.$name.'" does not exist in class "'.static::class.'"'
84
        );
85
    }
86
87
    /**
88
     * Get a fresh instance of this class.
89
     *
90
     * @return UrlOptions
91
     */
92
    public static function instance(): self
93
    {
94
        return new static();
95
    }
96
97
    /**
98
     * Set the $urlRoute to work with in the Neurony\Url\Traits\HasUrl trait.
99
     *
100
     * @param string $controller
101
     * @param string $action
102
     * @return UrlOptions
103
     */
104
    public function routeUrlTo(string $controller, string $action): self
105
    {
106
        $this->routeController = $controller;
107
        $this->routeAction = $action;
108
109
        return $this;
110
    }
111
112
    /**
113
     * Set the $fromField to work with in the Neurony\Url\Traits\HasUrl trait.
114
     *
115
     * @param string|array|callable $field
116
     * @return UrlOptions
117
     */
118
    public function generateUrlSlugFrom($field): self
119
    {
120
        $this->fromField = $field;
121
122
        return $this;
123
    }
124
125
    /**
126
     * Set the $toField to work with in the Neurony\Url\Traits\HasUrl trait.
127
     *
128
     * @param string $field
129
     * @return UrlOptions
130
     */
131
    public function saveUrlSlugTo(string $field): self
132
    {
133
        $this->toField = $field;
134
135
        return $this;
136
    }
137
138
    /**
139
     * Set the $urlPrefix to work with in the Neurony\Url\Traits\HasUrl trait.
140
     *
141
     * @param string|array|callable $prefix
142
     * @return UrlOptions
143
     */
144
    public function prefixUrlWith($prefix): self
145
    {
146
        $this->urlPrefix = $prefix;
147
148
        return $this;
149
    }
150
151
    /**
152
     * Set the $urlSuffix to work with in the Neurony\Url\Traits\HasUrl trait.
153
     *
154
     * @param string|array|callable $suffix
155
     * @return UrlOptions
156
     */
157
    public function suffixUrlWith($suffix): self
158
    {
159
        $this->urlSuffix = $suffix;
160
161
        return $this;
162
    }
163
164
    /**
165
     * Set the $urlGlue to work with in the Neurony\Url\Traits\HasUrl trait.
166
     *
167
     * @param string $glue
168
     * @return UrlOptions
169
     */
170
    public function glueUrlWith(string $glue): self
171
    {
172
        $this->urlGlue = $glue;
173
174
        return $this;
175
    }
176
177
    /**
178
     * Set the $cascadeUpdate to work with in the Neurony\Url\Traits\HasUrl trait.
179
     *
180
     * @return UrlOptions
181
     */
182
    public function doNotUpdateCascading(): self
183
    {
184
        $this->cascadeUpdate = false;
185
186
        return $this;
187
    }
188
}
189