Profiler_Table_Core   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 57
rs 10
wmc 5
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A styles() 0 11 2
A add_column() 0 4 1
A add_row() 0 4 1
A render() 0 6 1
1
<?php defined('SYSPATH') or die('No direct access allowed.');
2
/**
3
 * Provides a table layout for sections in the Profiler library.
4
 *
5
 * $Id$
6
 *
7
 * @package    Profiler
8
 * @author     Kohana Team
9
 * @copyright  (c) 2007-2008 Kohana Team
10
 * @license    http://kohanaphp.com/license.html
11
 */
12
class Profiler_Table_Core
13
{
14
    protected $columns = array();
15
    protected $rows = array();
16
17
    /**
18
     * Get styles for table.
19
     *
20
     * @return  string
21
     */
22
    public function styles()
23
    {
24
        static $styles_output;
25
26
        if (! $styles_output) {
27
            $styles_output = true;
28
            return file_get_contents(Kohana::find_file('views', 'kohana_profiler_table', false, 'css'));
0 ignored issues
show
Documentation introduced by
'css' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
        }
30
31
        return '';
32
    }
33
34
    /**
35
     * Add column to table.
36
     *
37
     * @param  string  CSS class
38
     * @param  string  CSS style
39
     */
40
    public function add_column($class = '', $style = '')
41
    {
42
        $this->columns[] = array('class' => $class, 'style' => $style);
43
    }
44
45
    /**
46
     * Add row to table.
47
     *
48
     * @param  array   data to go in table cells
49
     * @param  string  CSS class
50
     * @param  string  CSS style
51
     */
52
    public function add_row($data, $class = '', $style = '')
53
    {
54
        $this->rows[] = array('data' => $data, 'class' => $class, 'style' => $style);
55
    }
56
57
    /**
58
     * Render table.
59
     *
60
     * @return  string
61
     */
62
    public function render()
63
    {
64
        $data['rows'] = $this->rows;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
65
        $data['columns'] = $this->columns;
66
        return View::factory('kohana_profiler_table', $data)->render();
67
    }
68
}
69