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

Completed
Pull Request — master (#282)
by Cristian
05:55 queued 03:14
created

FakeColumns::getFakeColumnsAsArray()   C

Complexity

Conditions 8
Paths 12

Size

Total Lines 31
Code Lines 14

Duplication

Lines 3
Ratio 9.68 %

Importance

Changes 0
Metric Value
cc 8
eloc 14
nc 12
nop 1
dl 3
loc 31
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\PanelTraits;
4
5
trait FakeColumns
6
{
7
    /**
8
     * Returns an array of database columns names, that are used to store fake values.
9
     * Returns ['extras'] if no columns have been found.
10
     */
11
    public function getFakeColumnsAsArray($form = 'create')
12
    {
13
        $fake_field_columns_to_encode = [];
14
15
        // get the right fields according to the form type (create/update)
16
        $fields = $this->getFields($form);
0 ignored issues
show
Bug introduced by
It seems like getFields() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
17
18
        foreach ($fields as $k => $field) {
19
            // if it's a fake field
20
            if (isset($fields[$k]['fake']) && $fields[$k]['fake'] == true) {
21
                // add it to the request in its appropriate variable - the one defined, if defined
22
                if (isset($fields[$k]['store_in'])) {
23 View Code Duplication
                    if (! in_array($fields[$k]['store_in'], $fake_field_columns_to_encode, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
                        array_push($fake_field_columns_to_encode, $fields[$k]['store_in']);
25
                    }
26
                } else {
27
                    //otherwise in the one defined in the $crud variable
28
29
                    if (! in_array('extras', $fake_field_columns_to_encode, true)) {
30
                        array_push($fake_field_columns_to_encode, 'extras');
31
                    }
32
                }
33
            }
34
        }
35
36
        if (! count($fake_field_columns_to_encode)) {
37
            return ['extras'];
38
        }
39
40
        return $fake_field_columns_to_encode;
41
    }
42
}
43