Passed
Push — master ( 9a2ce8...395129 )
by Patrick
02:01
created

HandlerTable::renderLine()   C

Complexity

Conditions 13
Paths 35

Size

Total Lines 73
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 13
eloc 43
nc 35
nop 1
dl 0
loc 73
rs 6.6166
c 1
b 0
f 1

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
namespace Icinga\Module\Trapdirector\Tables;
4
5
use Icinga\Web\Url;
6
7
class HandlerTable extends TrapDirectorTable
8
{
9
10
    protected $status_display=array(
11
        -2	=>'ignore',
12
        -1 => '-',
13
        0	=> 'OK',
14
        1	=> 'warning',
15
        2	=> 'critical',
16
        3	=> 'unknown',);
17
    
18
    // translate
19
    protected $doTranslate=false;
20
    protected $MIB;
21
    
22
    public function setMibloader($mibloader)
23
    {
24
        $this->MIB=$mibloader;
25
        $this->doTranslate=true;
26
    }
27
28
    
29
    public function getCurrentURL()
30
    {
31
        return Url::fromPath($this->urlPath . '/handler');
32
    }
33
    
34
    public function renderLine($row)
35
      {
36
          $html = '';
37
          $firstCol = true;
38
               
39
          $titleNames = array_keys($this->titles);
40
          foreach ($titleNames as $rowkey )
41
          {        
42
              // Check missing value
43
              if (property_exists($row, $rowkey))
44
              {
45
                  switch ($rowkey)
46
                  {
47
                      case 'action_match': // display text levels
48
                      case 'action_nomatch':
49
                          $val=$this->status_display[$row->$rowkey];
50
                          break;
51
                      case 'trap_oid': // try to traslate oids.
52
                          
53
                          if ($this->doTranslate === true)
54
                          {
55
                              $oidName = $this->MIB->translateOID($row->$rowkey);
56
                              if (isset($oidName['name']))
57
                              {
58
                                  $val=$oidName['name'];
59
                              }
60
                              else
61
                              {
62
                                  $val = $row->$rowkey;
63
                              }
64
                          }
65
                          else
66
                          {
67
                              $val = $row->$rowkey;
68
                          }
69
                          break;
70
                      case 'host_name': // switch to hostgroup if name is null
71
                          if ($row->$rowkey == null)
72
                          {
73
                              $val = $row->host_group_name;
74
                          }
75
                          else
76
                          {
77
                              $val = $row->$rowkey;
78
                          }
79
                          break;
80
                      default:
81
                          $val = $row->$rowkey;
82
                  }
83
                  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
84
                  {
85
                      
86
                  }
87
              } else {
88
                  $val = '-';
89
              }
90
              if ($firstCol === true) { // Put link in first column for trap detail.
91
                  $html .= '<td>'
92
                      . $this->view->qlink(
93
                          $this->view->escape($val),
94
                          Url::fromPath(
95
                              $this->urlPath . '/handler/add',
96
                              array('ruleid' => $row->id)
97
                              )
98
                          )
99
                          . '</td>';
100
              } else {
101
                  $html .= '<td>' . $this->view->escape($val) . '</td>';
102
              }
103
              $firstCol=false;
104
              
105
          }
106
          return $html;
107
      }
108
109
}