Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Test Failed
Pull Request — master (#3996)
by
unknown
12:27
created

FieldsPrivateMethods::transformFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Traits;
4
5
trait FieldsPrivateMethods
6
{
7
    /**
8
     * Move the most recently added field before or after the given target field. Default is before.
9
     *
10
     * @param  array  $fields  The form fields.
11
     * @param  string  $targetFieldName  The target field name.
12
     * @param  bool  $before  If true, the field will be moved before the target field, otherwise it will be moved after it.
13
     * @return array
14
     */
15
    private function moveField($fields, $targetFieldName, $before = true)
16
    {
17
        if (array_key_exists($targetFieldName, $fields)) {
18
            $targetFieldPosition = $before ? array_search($targetFieldName, array_keys($fields))
19
                : array_search($targetFieldName, array_keys($fields)) + 1;
20
21
            if ($targetFieldPosition >= (count($fields) - 1)) {
22
                // target field name is same as element
23
                return $fields;
24
            }
25
26
            $element = array_pop($fields);
27
            $beginningArrayPart = array_slice($fields, 0, $targetFieldPosition, true);
0 ignored issues
show
Bug introduced by
It seems like $targetFieldPosition can also be of type string; however, parameter $length of array_slice() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            $beginningArrayPart = array_slice($fields, 0, /** @scrutinizer ignore-type */ $targetFieldPosition, true);
Loading history...
28
            $endingArrayPart = array_slice($fields, $targetFieldPosition, null, true);
0 ignored issues
show
Bug introduced by
It seems like $targetFieldPosition can also be of type string; however, parameter $offset of array_slice() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
            $endingArrayPart = array_slice($fields, /** @scrutinizer ignore-type */ $targetFieldPosition, null, true);
Loading history...
29
30
            $fields = array_merge($beginningArrayPart, [$element['name'] => $element], $endingArrayPart);
31
        }
32
33
        return $fields;
34
    }
35
36
    /**
37
     * Apply the given order to the fields and return the new array.
38
     *
39
     * @param  array  $fields  The fields array.
40
     * @param  array  $order  The desired field order array.
41
     * @return array The ordered fields array.
42
     */
43
    private function applyOrderToFields($fields, $order)
44
    {
45
        $orderedFields = [];
46
        foreach ($order as $fieldName) {
47
            if (array_key_exists($fieldName, $fields)) {
48
                $orderedFields[$fieldName] = $fields[$fieldName];
49
            }
50
        }
51
52
        if (empty($orderedFields)) {
53
            return $fields;
54
        }
55
56
        $remaining = array_diff_key($fields, $orderedFields);
57
58
        return array_merge($orderedFields, $remaining);
59
    }
60
61
    /**
62
     * Apply the given callback to the form fields.
63
     *
64
     * @param  callable  $callback  The callback function to run for the given form fields.
65
     */
66
    private function transformFields(callable $callback)
67
    {
68
        $this->setOperationSetting('fields', $callback($this->getCleanStateFields()));
0 ignored issues
show
Bug introduced by
It seems like setOperationSetting() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $this->/** @scrutinizer ignore-call */ 
69
               setOperationSetting('fields', $callback($this->getCleanStateFields()));
Loading history...
69
    }
70
71
    /**
72
     * Returns the fields as they are stored inside operation setting, not running the
73
     * presentation callbacks like converting the `dot.names` into `dot[names]` for html for example.
74
     */
75
    private function getCleanStateFields()
76
    {
77
        return $this->getOperationSetting('fields') ?? [];
0 ignored issues
show
Bug introduced by
It seems like getOperationSetting() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        return $this->/** @scrutinizer ignore-call */ getOperationSetting('fields') ?? [];
Loading history...
78
    }
79
}
80