GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — 3.0.x ( 7946ec...895393 )
by Nicolas
04:19
created

buildKeyDefinitionFromArray()   C

Complexity

Conditions 11
Paths 78

Size

Total Lines 51
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 32
c 1
b 0
f 0
nc 78
nop 2
dl 0
loc 51
rs 5.7333

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @package toolkit
5
 */
6
7
trait DatabaseKeyDefinition
8
{
9
    /**
10
     * @internal
11
     * Given a field name valid field $k, this methods build a key definition
12
     * SQL part from an array of options. It will use the array $options to generate
13
     * the a complete SQL definition part, with all its possible properties.
14
     *
15
     * @param string $k
16
     *  The name of the key
17
     * @param string|array $options
18
     *  All the options needed to properly create the key.
19
     *  When the value is a string, it is considered as the key's type.
20
     * @param string $options.type
21
     *  The SQL type of the key.
22
     *  Valid values are: 'key', 'unique', 'primary', 'fulltext', 'index'
23
     * @param string|array $options.cols
24
     *  The list of columns to be included in the key.
25
     *  If omitted, the name of the key be added as the only column in the key.
26
     * @return string
27
     *  The SQL part containing the key definition.
28
     * @throws DatabaseStatementException
29
     */
30
    public function buildKeyDefinitionFromArray($k, $options)
31
    {
32
        if (is_string($options)) {
33
            $options = ['type' => $options];
34
        } elseif (!is_array($options)) {
0 ignored issues
show
introduced by
The condition is_array($options) is always true.
Loading history...
35
            throw new DatabaseStatementException('Key value can only be a string or an array');
36
        } elseif (!isset($options['type'])) {
37
            throw new DatabaseStatementException('Key type must be defined.');
38
        }
39
        $type = strtolower($options['type']);
40
        $k = $this->asTickedString($k);
0 ignored issues
show
Bug introduced by
It seems like asTickedString() 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

40
        /** @scrutinizer ignore-call */ 
41
        $k = $this->asTickedString($k);
Loading history...
41
        $cols = isset($options['cols']) ? $options['cols'] : $k;
42
        $typeIndex = in_array($type, [
43
            'key', 'unique', 'primary', 'fulltext', 'index'
44
        ]);
45
        if ($typeIndex === false) {
46
            throw new DatabaseStatementException("Key of type `$type` is not valid");
47
        }
48
        switch ($type) {
49
            case 'unique':
50
                $type = strtoupper($type) . ' KEY';
51
                break;
52
            case 'primary':
53
                // Use the key name as the KEY keyword
54
                // since the primary key does not have a name
55
                $k = 'KEY';
56
                // fall through
57
            default:
58
                $type = strtoupper($type);
59
                break;
60
        }
61
62
        // Format columns including size
63
        $colsFormatted = [];
64
65
        if (!is_array($cols)) {
66
            $cols = [$cols];
67
        }
68
69
        foreach ($cols as $key => $value) {
70
            // No Size
71
            if (General::intval($key) !== -1) {
72
                $colsFormatted[] = $this->asTickedString($value);
73
            // Size
74
            } else {
75
                $colsFormatted[] = $this->asTickedString($key) . '(' . $value . ')';
76
            }
77
        }
78
        $colsFormatted = implode(self::LIST_DELIMITER, $colsFormatted);
0 ignored issues
show
Bug introduced by
The constant DatabaseKeyDefinition::LIST_DELIMITER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
79
80
        return "$type $k ($colsFormatted)";
81
    }
82
}
83