Passed
Push — v1 ( 061017...1b920b )
by Andrew
11:00 queued 06:43
created

CompleteItem::command()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * Twigfield for Craft CMS
4
 *
5
 * Provides a twig editor field with Twig & Craft API autocomplete
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2022 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\twigfield\models;
12
13
use craft\base\Model;
14
use craft\validators\ArrayValidator;
15
use nystudio107\twigfield\base\AutocompleteInterface;
16
use nystudio107\twigfield\types\CompleteItemKind;
17
18
/**
19
 * Based on: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.CompletionItem.html
20
 *
21
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
22
 * @package   Twigfield
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
23
 * @since     1.0.11
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
24
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
25
class CompleteItem extends Model
26
{
27
    // Public Static Methods
28
    // =========================================================================
29
30
    /**
31
     * Factory method for complete item objects
32
     *
33
     * @return CompleteItem
34
     */
35
    public static function create(): CompleteItem
36
    {
37
        return new CompleteItem();
38
    }
39
40
    // Public Properties
41
    // =========================================================================
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @var array An optional array of additional text edits that are applied when selecting this completion.
45
     * Edits must not overlap with the main edit nor with themselves.
46
     * ref: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ISingleEditOperation.html
47
     */
48
    public $additionalTextEdits;
49
50
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
51
     * @var array A command that should be run upon acceptance of this item.
52
     * ref: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.Command.html
53
     */
54
    public $command;
55
56
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
57
     * @var array An optional set of characters that when pressed while this completion is active will accept
58
     * it first and then type that character. Note that all commit characters should have `length=1` and that
59
     * superfluous characters will be ignored.
60
     */
61
    public $commitCharacters;
62
63
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
64
     * @var string A human-readable string with additional information about this item, like type or symbol information.
65
     */
66
    public $detail;
67
68
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
69
     * @var string A human-readable string that represents a doc-comment.
70
     * Can contain Markdown
71
     */
72
    public $documentation;
73
74
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
75
     * @var string A string that should be used when filtering a set of completion items.
76
     * When falsy the `label` is used.
77
     */
78
    public $filterText;
79
80
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
81
     * @var string A string or snippet that should be inserted in a document when selecting this completion.
82
     */
83
    public $insertText = '';
84
85
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
     * @var int Additional rules (as bitmask) that should be applied when inserting this completion.
87
     */
88
    public $insertTextRules;
89
90
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
91
     * @var int The kind of this completion item. Based on the kind an icon is chosen by the editor.
92
     */
93
    public $kind = CompleteItemKind::PropertyKind;
94
95
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
96
     * @var string The label of this completion item. By default this is also the text that is inserted
97
     * when selecting this completion.
98
     */
99
    public $label;
100
101
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
102
     * @var bool Select this item when showing. Note that only one completion item can be selected and that
103
     * the editor decides which item that is. The rule is that the first item of those that match best is selected.
104
     */
105
    public $preselect;
106
107
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
108
     * @var array A range of text that should be replaced by this completion item.
109
     */
110
    public $range;
111
112
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
113
     * @var string A string that should be used when comparing this item with other items. When falsy
114
     * the `label` is used.
115
     */
116
    public $sortText;
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119
     * @var array A modifier to the kind which affect how the item is rendered, e.g. Deprecated is rendered
120
     * with a strikeout
121
     */
122
    public $tags;
123
124
    // Public Methods
125
    // =========================================================================
126
127
    /**
128
     * An optional array of additional text edits that are applied when selecting this completion.
129
     * Edits must not overlap with the main edit nor with themselves.
130
     * ref: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ISingleEditOperation.html
131
     * @param $value array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
132
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
133
    public function additionalTextEdits($value): self
134
    {
135
        $this->additionalTextEdits = $value;
136
        return $this;
137
    }
138
139
    /**
140
     * A command that should be run upon acceptance of this item.
141
     * ref: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.Command.html
142
     * @param $value array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
143
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
144
    public function command($value): self
145
    {
146
        $this->command = $value;
147
        return $this;
148
    }
149
150
    /**
151
     * An optional set of characters that when pressed while this completion is active will accept
152
     * it first and then type that character. Note that all commit characters should have `length=1` and that
153
     * superfluous characters will be ignored.
154
     * @param $value array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
155
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
156
    public function commitCharacters($value): self
157
    {
158
        $this->commitCharacters = $value;
159
        return $this;
160
    }
161
162
    /**
163
     * A human-readable string with additional information about this item, like type or symbol information.
164
     * @param $value string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
165
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
166
    public function detail($value): self
167
    {
168
        $this->detail = $value;
169
        return $this;
170
    }
171
172
    /**
173
     * A human-readable string that represents a doc-comment.
174
     * Can contain Markdown
175
     * @param $value string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
176
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
177
    public function documentation($value): self
178
    {
179
        $this->documentation = $value;
180
        return $this;
181
    }
182
183
    /**
184
     * A string that should be used when filtering a set of completion items.
185
     * When falsy the `label` is used.
186
     * @param $value string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
187
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
188
    public function filterText($value): self
189
    {
190
        $this->filterText = $value;
191
        return $this;
192
    }
193
194
    /**
195
     * A string or snippet that should be inserted in a document when selecting this completion.
196
     * @param $value string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
197
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
198
    public function insertText($value): self
199
    {
200
        $this->insertText = $value;
201
        return $this;
202
    }
203
204
    /**
205
     * Additional rules (as bitmask) that should be applied when inserting this completion.
206
     * @param $value int
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
207
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
208
    public function insertTextRules($value): self
209
    {
210
        $this->insertTextRules = $value;
211
        return $this;
212
    }
213
214
    /**
215
     * The kind of this completion item. Based on the kind an icon is chosen by the editor.
216
     * @param $value int
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
217
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
218
    public function kind($value): self
219
    {
220
        $this->kind = $value;
221
        return $this;
222
    }
223
224
    /**
225
     * The label of this completion item. By default this is also the text that is inserted
226
     * when selecting this completion.
227
     * @param $value string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
228
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
229
    public function label($value): self
230
    {
231
        $this->label = $value;
232
        return $this;
233
    }
234
235
    /**
236
     * Select this item when showing. Note that only one completion item can be selected and that
237
     * the editor decides which item that is. The rule is that the first item of those that match best is selected.
238
     * @param $value bool
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
239
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
240
    public function preselect($value): self
241
    {
242
        $this->preselect = $value;
243
        return $this;
244
    }
245
246
    /**
247
     * A range of text that should be replaced by this completion item.
248
     * @param $value array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
249
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
250
    public function range($value): self
251
    {
252
        $this->range = $value;
253
        return $this;
254
    }
255
256
    /**
257
     * A string that should be used when comparing this item with other items. When falsy
258
     * the `label` is used.
259
     * @param $value string
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
260
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
261
    public function sortText($value): self
262
    {
263
        $this->sortText = $value;
264
        return $this;
265
    }
266
267
    /**
268
     * A modifier to the kind which affect how the item is rendered, e.g. Deprecated is rendered
269
     * with a strikeout
270
     * @param $value array
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
271
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
272
    public function tags($value): self
273
    {
274
        $this->tags = $value;
275
        return $this;
276
    }
277
278
    /**
279
     * Add the completion item to the passed in AutocompleteInterface static class
280
     *
281
     * @param AutocompleteInterface $autocomplete
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
282
     * @param string $path The . delimited path in the autocomplete array to the item; if omitted, will be set to the $item->label
0 ignored issues
show
Coding Style introduced by
Expected 16 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 9 spaces after parameter name; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
283
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
284
     */
285
    public function add($autocomplete, string $path = ''): void
286
    {
287
        $autocomplete->addCompleteItem($this, $path);
288
    }
289
290
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
291
     * @inheritdoc
292
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
293
    public function defineRules(): array
294
    {
295
        return [
296
297
            [
298
                [
299
                    'detail',
300
                    'documentation',
301
                    'filterText',
302
                    'insertText',
303
                    'label',
304
                    'sortText',
305
                    'tags',
306
                ],
307
                'string'
308
            ],
309
            [
310
                [
311
                    'additionalTextEdits',
312
                    'command',
313
                    'commitCharacters',
314
                    'range',
315
                ],
316
                ArrayValidator::class
317
            ],
318
            ['insertTextRules', 'integer', 'min' => 0, 'max' => 4],
319
            ['kind', 'integer', 'min' => 0, 'max' => 27],
320
            ['preselect', 'boolean'],
321
            [
322
                [
323
                    'insertText',
324
                    'kind',
325
                ],
326
                'required'
327
            ],
328
        ];
329
    }
330
}
331