Issues (1783)

src/models/Settings.php (40 issues)

1
<?php
2
/**
3
 * Retour plugin for Craft CMS
4
 *
5
 * Retour allows you to intelligently redirect legacy URLs, so that you don't
6
 * lose SEO value when rebuilding & restructuring a website
7
 *
8
 * @link      https://nystudio107.com/
0 ignored issues
show
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2018 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\retour\models;
13
14
use craft\base\Model;
15
use craft\behaviors\EnvAttributeParserBehavior;
16
use craft\validators\ArrayValidator;
17
18
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Retour
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     3.0.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
23
class Settings extends Model
24
{
25
    // Public Properties
26
    // =========================================================================
27
28
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
29
     * @var string The public-facing name of the plugin
30
     */
31
    public string $pluginName = 'Retour';
32
33
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
34
     * @var bool Controls whether Retour automatically creates static redirects
35
     *      when an entry's URI changes.
36
     */
37
    public bool $createUriChangeRedirects = true;
38
39
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
40
     * @var string Should the legacy URL be matched by path (e.g.
41
     *      `/new-recipes/`) or by full URL (e.g.:
42
     *      `http://example.com/de/new-recipes/`)?
43
     */
44
    public string $uriChangeRedirectSrcMatch = 'pathonly';
45
46
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
47
     * @var bool Should the query string be stripped from all 404 URLs before
48
     *      their evaluation?
49
     */
50
    public bool $alwaysStripQueryString = false;
51
52
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
53
     * @var bool Should the query string be preserved and passed along to the
54
     *      redirected URL?
55
     */
56
    public bool $preserveQueryString = false;
57
58
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
59
     * @var bool Should `no-cache` headers be set on the redirect response to prevent client-side caching?
60
     */
61
    public bool $setNoCacheHeaders = true;
62
63
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
64
     * @var bool Should the anonymous ip address of the client causing a 404 be
65
     *      recorded?
66
     */
67
    public bool $recordRemoteIp = true;
68
69
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
70
     * @var int How many static redirects to display in the Control Panel
71
     */
72
    public int $staticRedirectDisplayLimit = 100;
73
74
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
75
     * @var int How many dynamic redirects to display in the Control Panel
76
     */
77
    public int $dynamicRedirectDisplayLimit = 100;
78
79
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
80
     * @var bool Should the query string be stripped from the saved statistics
81
     *      source URLs?
82
     */
83
    public bool $stripQueryStringFromStats = true;
84
85
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
86
     * @var int How many stats should be stored
87
     */
88
    public int $statsStoredLimit = 1000;
89
90
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
91
     * @var int Dashboard data live refresh interval
92
     */
93
    public int $refreshIntervalSecs = 5;
94
95
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
96
     * @var bool Whether the Statistics should be trimmed after each new
97
     *      statistic is recorded
98
     */
99
    public bool $automaticallyTrimStatistics = true;
100
101
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
102
     * @var bool Whether statistics should be kept to track how many times
103
     *      a redirect has been followed
104
     */
105
    public $enableStatistics = true;
106
107
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
108
     * @var int The number of milliseconds required between trimming of
109
     *      statistics
110
     */
111
    public int $statisticsRateLimitMs = 3600000;
112
113
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
114
     * @var int How many stats to display in the Control Panel
115
     */
116
    public int $statsDisplayLimit = 1000;
117
118
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
119
     * @var bool Determines whether the Retour API endpoint should be enabled for anonymous frontend access
120
     */
121
    public bool $enableApiEndpoint = false;
122
123
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
124
     * @var array [Regular expressions](https://regexr.com/) to match URLs to
125
     *      exclude from Retour
126
     */
127
    public array $excludePatterns = [
128
    ];
129
130
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
131
     * @var array Additional headers to add to redirected requests
132
     */
133
    public array $additionalHeaders = [
134
    ];
135
136
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
137
     * @var string The delimiter between data column values for importing CSV files (normally `,`)
138
     */
139
    public string $csvColumnDelimiter = ',';
140
141
    // Public Methods
142
    // =========================================================================
143
144
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
145
     * @inheritdoc
146
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
147
    public function rules(): array
148
    {
149
        return [
150
            ['pluginName', 'string'],
151
            ['pluginName', 'default', 'value' => 'Retour'],
152
            [
153
                [
154
                    'createUriChangeRedirects',
155
                    'alwaysStripQueryString',
156
                    'preserveQueryString',
157
                    'stripQueryStringFromStats',
158
                    'recordRemoteIp',
159
                ],
160
                'boolean',
161
            ],
162
            ['uriChangeRedirectSrcMatch', 'default', 'value' => 'pathonly'],
163
            ['uriChangeRedirectSrcMatch', 'string'],
164
            ['uriChangeRedirectSrcMatch', 'in', 'range' => [
165
                'pathonly',
166
                'fullurl',
167
            ]],
168
            ['staticRedirectDisplayLimit', 'integer', 'min' => 1],
169
            ['staticRedirectDisplayLimit', 'default', 'value' => 100],
170
            ['dynamicRedirectDisplayLimit', 'integer', 'min' => 1],
171
            ['dynamicRedirectDisplayLimit', 'default', 'value' => 100],
172
            ['statsStoredLimit', 'integer', 'min' => 1],
173
            ['statsStoredLimit', 'default', 'value' => 1000],
174
            ['refreshIntervalSecs', 'integer', 'min' => 0],
175
            ['refreshIntervalSecs', 'default', 'value' => 3],
176
            ['statsDisplayLimit', 'integer', 'min' => 1],
177
            ['statsDisplayLimit', 'default', 'value' => 1000],
178
            [
179
                [
180
                    'excludePatterns',
181
                    'additionalHeaders',
182
                ],
183
                ArrayValidator::class,
184
            ],
185
        ];
186
    }
187
188
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
189
     * @return array
190
     */
191
    public function behaviors(): array
192
    {
193
        return [
194
            'parser' => [
195
                'class' => EnvAttributeParserBehavior::class,
196
                'attributes' => [
197
                ],
198
            ],
199
        ];
200
    }
201
}
202