Kint_Parser_Table::parse()   D
last analyzed

Complexity

Conditions 10
Paths 13

Size

Total Lines 42
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 21
nc 13
nop 3
dl 0
loc 42
rs 4.8196
c 0
b 0
f 0

How to fix   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
class Kint_Parser_Table extends Kint_Parser_Plugin
0 ignored issues
show
Coding Style introduced by
Kint_Parser_Table does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
4
{
5
    public function getTypes()
6
    {
7
        return array('array');
8
    }
9
10
    public function getTriggers()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
11
    {
12
        return Kint_Parser::TRIGGER_SUCCESS;
13
    }
14
15
    public function parse(&$var, Kint_Object &$o, $trigger)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
16
    {
17
        if (empty($o->value->contents)) {
18
            return;
19
        }
20
21
        $array = $this->parser->getCleanArray($var);
22
23
        if (count($array) < 2) {
24
            return;
25
        }
26
27
        // Ensure this is an array of arrays and that all child arrays have the
28
        // same keys. We don't care about their children - if there's another
29
        // "table" inside we'll just make another one down the value tab
30
        $keys = null;
31
        foreach ($array as $elem) {
32
            if (!is_array($elem) || count($elem) < 2) {
33
                return;
34
            } elseif ($keys === null) {
35
                $keys = array_keys($elem);
36
            } elseif (array_keys($elem) !== $keys) {
37
                return;
38
            }
39
        }
40
41
        // Ensure none of the child arrays are recursion or depth limit. We
42
        // don't care if their children are since they are the table cells
43
        foreach ($o->value->contents as $childarray) {
44
            if (empty($childarray->value->contents)) {
45
                return;
46
            }
47
        }
48
49
        // Objects by reference for the win! We can do a copy-paste of the value
50
        // representation contents and just slap a new hint on there and hey
51
        // presto we have our table representation with no extra memory used!
52
        $table = new Kint_Object_Representation('Table');
53
        $table->contents = $o->value->contents;
54
        $table->hints[] = 'table';
55
        $o->addRepresentation($table, 0);
56
    }
57
}
58