Issues (447)

src/helpers/Field.php (36 issues)

1
<?php
2
/**
3
 * Route Map plugin for Craft CMS
4
 *
5
 * Returns a list of public routes for elements with URLs
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) 2017 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\routemap\helpers;
12
13
use craft\base\Component;
14
use craft\base\ElementInterface;
0 ignored issues
show
The type craft\base\ElementInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use craft\base\Field as BaseField;
16
use craft\elements\Entry;
17
use craft\models\FieldLayout;
18
use yii\base\InvalidConfigException;
19
20
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
21
 * @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...
22
 * @package   RouteMap
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
23
 * @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...
24
 */
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...
25
class Field extends Component
26
{
27
    // Static Methods
28
    // =========================================================================
29
    /**
30
     * Return all the fields in the $element of the type $fieldType class
31
     *
32
     * @param ElementInterface $element
0 ignored issues
show
Missing parameter comment
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
33
     * @param string $fieldType
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 11 spaces after parameter type; 1 found
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
34
     * @return array
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
35
     */
36
    public static function fieldsOfType(ElementInterface $element, string $fieldType): array
37
    {
38
        $foundFields = [];
39
40
        $layout = $element->getFieldLayout();
41
        if (!$layout instanceof FieldLayout) {
42
            return [];
43
        }
44
45
        $fields = $layout->getCustomFields();
46
        /** @var BaseField $field */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
47
        foreach ($fields as $field) {
48
            if ($field instanceof $fieldType) {
49
                $foundFields[] = $field->handle;
50
            }
51
        }
52
53
        return $foundFields;
54
    }
55
56
    /**
57
     * Return all the fields in the $matrixBlock of the type $fieldType class
58
     *
59
     * @param Entry $matrixEntry
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
60
     * @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...
61
     * @return ?array
0 ignored issues
show
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
62
     */
63
    public static function matrixFieldsOfType(Entry $matrixEntry, string $fieldType): ?array
64
    {
65
        $foundFields = [];
66
67
        try {
68
            $matrixEntryTypeModel = $matrixEntry->getType();
69
        } catch (InvalidConfigException $e) {
70
            $matrixEntryTypeModel = null;
71
        }
72
        if ($matrixEntryTypeModel) {
73
            $fields = $matrixEntryTypeModel->getCustomFields();
74
            /** @var BaseField $field */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
75
            foreach ($fields as $field) {
76
                if ($field instanceof $fieldType) {
77
                    $foundFields[$field->handle] = $field->name;
78
                }
79
            }
80
        }
81
82
        return $foundFields;
83
    }
84
}
85