Healthd   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 134
Duplicated Lines 42.54 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 57
loc 134
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 19 19 5
A _temperature() 19 19 1
A _fans() 19 19 1
B _voltage() 0 32 1
A build() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * healthd sensor class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Sensor
9
 * @author    Michael Cramer <[email protected]>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
12
 * @version   SVN: $Id: class.healthd.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * getting information from healthd
17
 *
18
 * @category  PHP
19
 * @package   PSI_Sensor
20
 * @author    Michael Cramer <[email protected]>
21
 * @copyright 2009 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
23
 * @version   Release: 3.0
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
26
class Healthd extends Sensors
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28
    /**
29
     * content to parse
30
     *
31
     * @var array
32
     */
33
    private $_lines = array();
34
35
    /**
36
     * fill the private content var through command or data access
37
     */
38 View Code Duplication
    public function __construct()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        parent::__construct();
41
        switch (defined('PSI_SENSOR_HEALTHD_ACCESS')?strtolower(PSI_SENSOR_HEALTHD_ACCESS):'command') {
42
        case 'command':
43
            $lines = "";
44
            CommonFunctions::executeProgram('healthdc', '-t', $lines);
45
            $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
46
            break;
47
        case 'data':
48
            if (CommonFunctions::rfts(APP_ROOT.'/data/healthd.txt', $lines)) {
49
                $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
50
            }
51
            break;
52
        default:
53
            $this->error->addConfigError('__construct()', 'PSI_SENSOR_HEALTHD_ACCESS');
54
            break;
55
        }
56
    }
57
58
    /**
59
     * get temperature information
60
     *
61
     * @return void
62
     */
63 View Code Duplication
    private function _temperature()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $ar_buf = preg_split("/\t+/", $this->_lines);
66
        $dev1 = new SensorDevice();
67
        $dev1->setName('temp1');
68
        $dev1->setValue($ar_buf[1]);
69
//        $dev1->setMax(70);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
        $this->mbinfo->setMbTemp($dev1);
0 ignored issues
show
Documentation introduced by
$dev1 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
71
        $dev2 = new SensorDevice();
72
        $dev2->setName('temp1');
73
        $dev2->setValue($ar_buf[2]);
74
//        $dev2->setMax(70);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
        $this->mbinfo->setMbTemp($dev2);
0 ignored issues
show
Documentation introduced by
$dev2 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
76
        $dev3 = new SensorDevice();
77
        $dev3->setName('temp1');
78
        $dev3->setValue($ar_buf[3]);
79
//        $dev3->setMax(70);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
80
        $this->mbinfo->setMbTemp($dev3);
0 ignored issues
show
Documentation introduced by
$dev3 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
81
    }
82
83
    /**
84
     * get fan information
85
     *
86
     * @return void
87
     */
88 View Code Duplication
    private function _fans()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $ar_buf = preg_split("/\t+/", $this->_lines);
91
        $dev1 = new SensorDevice();
92
        $dev1->setName('fan1');
93
        $dev1->setValue($ar_buf[4]);
94
//        $dev1->setMin(3000);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
        $this->mbinfo->setMbFan($dev1);
96
        $dev2 = new SensorDevice();
97
        $dev2->setName('fan2');
98
        $dev2->setValue($ar_buf[5]);
99
//        $dev2->setMin(3000);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
100
        $this->mbinfo->setMbFan($dev2);
101
        $dev3 = new SensorDevice();
102
        $dev3->setName('fan3');
103
        $dev3->setValue($ar_buf[6]);
104
//        $dev3->setMin(3000);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
        $this->mbinfo->setMbFan($dev3);
106
    }
107
108
    /**
109
     * get voltage information
110
     *
111
     * @return array voltage in array with lable
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
112
     */
113
    private function _voltage()
114
    {
115
        $ar_buf = preg_split("/\t+/", $this->_lines);
116
        $dev1 = new SensorDevice();
117
        $dev1->setName('Vcore1');
118
        $dev1->setValue($ar_buf[7]);
119
        $this->mbinfo->setMbVolt($dev1);
0 ignored issues
show
Documentation introduced by
$dev1 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
120
        $dev2 = new SensorDevice();
121
        $dev2->setName('Vcore2');
122
        $dev2->setValue($ar_buf[8]);
123
        $this->mbinfo->setMbVolt($dev2);
0 ignored issues
show
Documentation introduced by
$dev2 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
124
        $dev3 = new SensorDevice();
125
        $dev3->setName('3volt');
126
        $dev3->setValue($ar_buf[9]);
127
        $this->mbinfo->setMbVolt($dev3);
0 ignored issues
show
Documentation introduced by
$dev3 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
128
        $dev4 = new SensorDevice();
129
        $dev4->setName('+5Volt');
130
        $dev4->setValue($ar_buf[10]);
131
        $this->mbinfo->setMbVolt($dev4);
0 ignored issues
show
Documentation introduced by
$dev4 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
132
        $dev5 = new SensorDevice();
133
        $dev5->setName('+12Volt');
134
        $dev5->setValue($ar_buf[11]);
135
        $this->mbinfo->setMbVolt($dev5);
0 ignored issues
show
Documentation introduced by
$dev5 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
136
        $dev6 = new SensorDevice();
137
        $dev6->setName('-12Volt');
138
        $dev6->setValue($ar_buf[12]);
139
        $this->mbinfo->setMbVolt($dev6);
0 ignored issues
show
Documentation introduced by
$dev6 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
140
        $dev7 = new SensorDevice();
141
        $dev7->setName('-5Volt');
142
        $dev7->setValue($ar_buf[13]);
143
        $this->mbinfo->setMbVolt($dev7);
0 ignored issues
show
Documentation introduced by
$dev7 is of type object<SensorDevice>, but the function expects a object<Sensor>.

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...
144
    }
145
146
    /**
147
     * get the information
148
     *
149
     * @see PSI_Interface_Sensor::build()
150
     *
151
     * @return Void
152
     */
153
    public function build()
154
    {
155
        $this->_temperature();
156
        $this->_fans();
157
        $this->_voltage();
158
    }
159
}
160