Test Setup Failed
Push — test ( 7a62bf...87b5e8 )
by Jonathan
03:25
created

Renderer::sortPropertiesFull()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Renderer;
4
5
use Kint\Object\BasicObject;
6
use Kint\Object\InstanceObject;
7
8
abstract class Renderer
0 ignored issues
show
Coding Style introduced by
Renderer does not seem to conform to the naming convention (^Abstract|Factory$).

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...
9
{
10
    const SORT_NONE = 0;
11
    const SORT_VISIBILITY = 1;
12
    const SORT_FULL = 2;
13
14
    protected $parameters;
15
16
    abstract public function render(BasicObject $o);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
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...
17
18
    /**
19
     * It's a constructor. It constructs.
20
     *
21
     * @param array $parameters Array with initial kint state information
22
     */
23
    public function __construct(array $parameters)
24
    {
25
        $this->parameters = $parameters;
26
    }
27
28
    /**
29
     * Returns the first compatible plugin available.
30
     *
31
     * @param array $plugins Array of hints to class strings
32
     * @param array $hints   Array of object hints
33
     *
34
     * @return array Array of hints to class strings filtered and sorted by object hints
35
     */
36
    public function matchPlugins(array $plugins, array $hints)
37
    {
38
        $out = array();
39
40
        foreach ($hints as $key) {
41
            if (isset($plugins[$key])) {
42
                $out[$key] = $plugins[$key];
43
            }
44
        }
45
46
        return $out;
47
    }
48
49
    public function parserPlugins(array $plugins)
50
    {
51
        return $plugins;
52
    }
53
54
    public function preRender()
55
    {
56
        return '';
57
    }
58
59
    public function postRender()
60
    {
61
        return '';
62
    }
63
64
    public static function sortPropertiesFull(BasicObject $a, BasicObject $b)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. 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...
Comprehensibility introduced by
Avoid variables with short names like $b. 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...
65
    {
66
        $sort = BasicObject::sortByAccess($a, $b);
67
        if ($sort) {
68
            return $sort;
69
        }
70
71
        $sort = BasicObject::sortByName($a, $b);
72
        if ($sort) {
73
            return $sort;
74
        }
75
76
        return InstanceObject::sortByHierarchy($a->owner_class, $b->owner_class);
77
    }
78
79
    /**
80
     * Sorts an array of BasicObject.
81
     *
82
     * @param BasicObject[] $contents Object properties to sort
83
     * @param int           $sort
84
     *
85
     * @return BasicObject[]
86
     */
87
    public static function sortProperties(array $contents, $sort)
88
    {
89
        switch ($sort) {
90
            case self::SORT_VISIBILITY:
91
                $containers = array(
92
                    BasicObject::ACCESS_PUBLIC => array(),
93
                    BasicObject::ACCESS_PROTECTED => array(),
94
                    BasicObject::ACCESS_PRIVATE => array(),
95
                    BasicObject::ACCESS_NONE => array(),
96
                );
97
98
                foreach ($contents as $item) {
99
                    $containers[$item->access][] = $item;
100
                }
101
102
                return call_user_func_array('array_merge', $containers);
103
            case self::SORT_FULL:
104
                usort($contents, array('Kint\\Renderer\\Renderer', 'sortPropertiesFull'));
105
                // fall through
106
            default:
107
                return $contents;
108
        }
109
    }
110
}
111