ModelFields::setConfig()   B
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 16
nop 2
dl 0
loc 20
ccs 14
cts 14
cp 1
crap 5
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Anavel\Crud\Abstractor\Eloquent\Traits;
4
5
trait ModelFields
6
{
7
    protected $fieldsPresentation = [];
8
    protected $formTypes = [];
9
    protected $validationRules = [];
10
    protected $functions = [];
11
    protected $defaults = [];
12
13
    /**
14
     * @param string $action
15
     */
16 14
    public function readConfig($action)
17
    {
18 14
        $this->fieldsPresentation = $this->getConfigValue('fields_presentation') ?: [];
0 ignored issues
show
Bug introduced by
It seems like getConfigValue() 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...
19 14
        $this->formTypes = $this->getConfigValue($action, 'form_types') ?: [];
0 ignored issues
show
Bug introduced by
It seems like getConfigValue() 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...
20 14
        $this->validationRules = $this->getConfigValue($action, 'validation') ?: [];
0 ignored issues
show
Bug introduced by
It seems like getConfigValue() 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...
21 14
        $this->functions = $this->getConfigValue($action, 'functions') ?: [];
0 ignored issues
show
Bug introduced by
It seems like getConfigValue() 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...
22 14
        $this->defaults = $this->getConfigValue($action, 'defaults') ?: [];
0 ignored issues
show
Bug introduced by
It seems like getConfigValue() 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...
23 14
    }
24
25
    /**
26
     * @param array  $config
27
     * @param string $columnName
28
     *
29
     * @return array
30
     */
31 14
    public function setConfig(array $config, $columnName)
32
    {
33 14
        if (array_key_exists($columnName, $this->formTypes)) {
34 4
            $config['form_type'] = $this->formTypes[$columnName];
35 4
        }
36
37 14
        if (array_key_exists($columnName, $this->validationRules)) {
38 4
            $config['validation'] = $this->validationRules[$columnName];
39 4
        }
40
41 14
        if (array_key_exists($columnName, $this->functions)) {
42 4
            $config['functions'] = $this->functions[$columnName];
43 4
        }
44
45 14
        if (array_key_exists($columnName, $this->defaults)) {
46 4
            $config['defaults'] = $this->defaults[$columnName];
47 4
        }
48
49 14
        return $config;
50
    }
51
}
52