Passed
Push — master ( 395129...4a18b4 )
by Patrick
01:56
created

HandlerTable::titleOrder()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 9
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
    public function setMibloader($mibloader)
23
    {
24
        $this->MIB=$mibloader;
25
        $this->doTranslate=true;
26
    }
27
28
    public function titleOrder($name)
29
    {
30
        switch ($name)
31
        {
32
            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...
33
            case 'source_ip' : return 'ip4'; break;
34
            default: return $this->content[$name];	
35
        }
36
        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...
37
    }
38
    
39
    public function getCurrentURL()
40
    {
41
        return Url::fromPath($this->urlPath . '/handler');
42
    }
43
    
44
    public function renderLine($row)
45
      {
46
          $html = '';
47
          $firstCol = true;
48
               
49
          $titleNames = array_keys($this->titles);
50
          foreach ($titleNames as $rowkey )
51
          {        
52
              // Check missing value
53
              if (property_exists($row, $rowkey))
54
              {
55
                  switch ($rowkey)
56
                  {
57
                      case 'action_match': // display text levels
58
                      case 'action_nomatch':
59
                          $val=$this->status_display[$row->$rowkey];
60
                          break;
61
                      case 'trap_oid': // try to traslate oids.
62
                          
63
                          if ($this->doTranslate === true)
64
                          {
65
                              $oidName = $this->MIB->translateOID($row->$rowkey);
66
                              if (isset($oidName['name']))
67
                              {
68
                                  $val=$oidName['name'];
69
                              }
70
                              else
71
                              {
72
                                  $val = $row->$rowkey;
73
                              }
74
                          }
75
                          else
76
                          {
77
                              $val = $row->$rowkey;
78
                          }
79
                          break;
80
                      case 'host_name': // switch to hostgroup if name is null
81
                          if ($row->$rowkey == null)
82
                          {
83
                              $val = $row->host_group_name;
84
                          }
85
                          else
86
                          {
87
                              $val = $row->$rowkey;
88
                          }
89
                          break;
90
                      default:
91
                          $val = $row->$rowkey;
92
                  }
93
                  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
94
                  {
95
                      
96
                  }
97
              } else {
98
                  $val = '-';
99
              }
100
              if ($firstCol === true) { // Put link in first column for trap detail.
101
                  $html .= '<td>'
102
                      . $this->view->qlink(
103
                          $this->view->escape($val),
104
                          Url::fromPath(
105
                              $this->urlPath . '/handler/add',
106
                              array('ruleid' => $row->id)
107
                              )
108
                          )
109
                          . '</td>';
110
              } else {
111
                  $html .= '<td>' . $this->view->escape($val) . '</td>';
112
              }
113
              $firstCol=false;
114
              
115
          }
116
          return $html;
117
      }
118
119
}