Issues (1181)

src/controllers/AutocompleteController.php (25 issues)

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
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2022 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
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...
10
11
namespace nystudio107\twigfield\controllers;
12
13
use craft\helpers\Json;
14
use craft\web\Controller;
15
use nystudio107\twigfield\Twigfield;
16
use yii\web\Response;
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   Twigfield
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.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 AutocompleteController extends Controller
24
{
25
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Parameter $action should have a doc-comment as per coding-style.
Loading history...
26
     * @inheritDoc
27
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
28
    public function beforeAction($action): bool
29
    {
30
        if (Twigfield::$settings->allowFrontendAccess) {
31
            $this->allowAnonymous = 1;
32
        }
33
34
        return parent::beforeAction($action);
35
    }
36
37
    /**
38
     * Return all of the autocomplete items in JSON format
39
     *
40
     * @param string $fieldType
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
41
     * @param string $twigfieldOptions
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
42
     * @return Response
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
43
     */
44
    public function actionIndex(string $fieldType = Twigfield::DEFAULT_FIELD_TYPE, string $twigfieldOptions = ''): Response
45
    {
46
        $options = [];
47
        $parsedJson = Json::decodeIfJson($twigfieldOptions);
48
        if (is_array($parsedJson)) {
49
            $options = $parsedJson;
50
        }
51
        $result = Twigfield::getInstance()->autocomplete->generateAutocompletes($fieldType, $options);
52
53
        return $this->asJson($result);
54
    }
55
}
56