Passed
Push — master ( 1d8afe...b3ce84 )
by Patrick
02:10
created

HandlerTable::setCategoriesArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
    // categories
23
    protected $categories = NULL;
24
    
25
    public function setCategoriesArray(array $categories)
26
    {
27
        $this->categories = $categories;
28
    }
29
    
30
    public function groupingPrintData( $value)
31
    {
32
        if ($this->groupingColumn == 'rule_type')
33
        {
34
            if ($this->categories == NULL || (! isset($this->categories[$value])))
35
                return 'Unknown category ('.$value.')';
36
            return 'Category : '. $this->categories[$value];
37
        }
38
        $html = "$value";
39
        return $html;
40
    }
41
    
42
    public function setMibloader($mibloader)
43
    {
44
        $this->MIB=$mibloader;
45
        $this->doTranslate=true;
46
    }
47
48
    public function titleOrder($name)
49
    {
50
        switch ($name)
51
        {
52
            case 'host_name' : return $this->content[$name]; break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
53
            case 'source_ip' : return 'ip4'; break;
54
            default: return $this->content[$name];	
55
        }
56
        return NULL;
0 ignored issues
show
Unused Code introduced by
return NULL is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
57
    }
58
    
59
    public function getCurrentURL()
60
    {
61
        return Url::fromPath($this->urlPath . '/handler');
62
    }
63
    
64
    public function renderLine($row)
65
      {
66
          $html = '';
67
          $firstCol = true;
68
               
69
          $titleNames = array_keys($this->titles);
70
          foreach ($titleNames as $rowkey )
71
          {        
72
              // Check missing value
73
              if (property_exists($row, $rowkey))
74
              {
75
                  switch ($rowkey)
76
                  {
77
                      case 'action_match': // display text levels
78
                      case 'action_nomatch':
79
                          $val=$this->status_display[$row->$rowkey];
80
                          break;
81
                      case 'trap_oid': // try to traslate oids.
82
                          
83
                          if ($this->doTranslate === true)
84
                          {
85
                              $oidName = $this->MIB->translateOID($row->$rowkey);
86
                              if (isset($oidName['name']))
87
                              {
88
                                  $val=$oidName['name'];
89
                              }
90
                              else
91
                              {
92
                                  $val = $row->$rowkey;
93
                              }
94
                          }
95
                          else
96
                          {
97
                              $val = $row->$rowkey;
98
                          }
99
                          break;
100
                      case 'host_name': // switch to hostgroup if name is null
101
                          if ($row->$rowkey == null)
102
                          {
103
                              $val = $row->host_group_name;
104
                          }
105
                          else
106
                          {
107
                              $val = $row->$rowkey;
108
                          }
109
                          break;
110
                      default:
111
                          $val = $row->$rowkey;
112
                  }
113
                  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
114
                  {
115
                      
116
                  }
117
              } else {
118
                  $val = '-';
119
              }
120
              if ($firstCol === true) { // Put link in first column for trap detail.
121
                  $html .= '<td class="traphover">'
122
                      . $this->view->qlink(
123
                          $this->view->escape($val),
124
                          Url::fromPath(
125
                              $this->urlPath . '/handler/add',
126
                              array('ruleid' => $row->id)
127
                              )
128
                          );
129
                  if ($row->comment != '')
130
                  {
131
                      $html.= '<span class="tohover">'. $row->comment .'</span></td>';
132
                  }
133
                  $html.= '</td>';
134
              } else {
135
                  $html .= '<td>' . $this->view->escape($val) . '</td>';
136
              }
137
              $firstCol=false;
138
              
139
          }
140
          return $html;
141
      }
142
143
}