MBM5::_fans()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * MBM5 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.mbm5.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * getting information from Motherboard Monitor 5
17
 * information retrival through csv file
18
 *
19
 * @category  PHP
20
 * @package   PSI_Sensor
21
 * @author    Michael Cramer <[email protected]>
22
 * @copyright 2009 phpSysInfo
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
24
 * @version   Release: 3.0
25
 * @link      http://phpsysinfo.sourceforge.net
26
 */
27
class MBM5 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...
28
{
29
    /**
30
     * array with the names of the labels
31
     *
32
     * @var array
33
     */
34
    private $_buf_label = array();
35
36
    /**
37
     * array withe the values
38
     *
39
     * @var array
40
     */
41
    private $_buf_value = array();
42
43
    /**
44
     * read the MBM5.csv file and fill the private arrays
45
     */
46
    public function __construct()
47
    {
48
        parent::__construct();
49
        $delim = "/;/";
50
        CommonFunctions::rfts(APP_ROOT."/data/MBM5.csv", $buffer);
51
        if (strpos($buffer, ";") === false) {
52
            $delim = "/,/";
53
        }
54
        $buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
55
        $this->_buf_label = preg_split($delim, substr($buffer[0], 0, -2), -1, PREG_SPLIT_NO_EMPTY);
56
        $this->_buf_value = preg_split($delim, substr($buffer[1], 0, -2), -1, PREG_SPLIT_NO_EMPTY);
57
    }
58
59
    /**
60
     * get temperature information
61
     *
62
     * @return void
63
     */
64 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...
65
    {
66
        for ($intPosi = 3; $intPosi < 6; $intPosi++) {
67
            if ($this->_buf_value[$intPosi] == 0) {
68
                continue;
69
            }
70
            preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
71
            $dev = new SensorDevice();
72
            $dev->setName($this->_buf_label[$intPosi]);
73
            $dev->setValue($hits[0]);
74
//            $dev->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($dev);
0 ignored issues
show
Documentation introduced by
$dev 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
        }
77
    }
78
79
    /**
80
     * get fan information
81
     *
82
     * @return void
83
     */
84 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...
85
    {
86
        for ($intPosi = 13; $intPosi < 16; $intPosi++) {
87
            if (!isset($this->_buf_value[$intPosi])) {
88
                continue;
89
            }
90
            preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
91
            $dev = new SensorDevice();
92
            $dev->setName($this->_buf_label[$intPosi]);
93
            $dev->setValue($hits[0]);
94
//            $dev->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($dev);
96
        }
97
    }
98
99
    /**
100
     * get voltage information
101
     *
102
     * @return void
103
     */
104 View Code Duplication
    private function _voltage()
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...
105
    {
106
        for ($intPosi = 6; $intPosi < 13; $intPosi++) {
107
            if ($this->_buf_value[$intPosi] == 0) {
108
                continue;
109
            }
110
            preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
111
            $dev = new SensorDevice();
112
            $dev->setName($this->_buf_label[$intPosi]);
113
            $dev->setValue($hits[0]);
114
            $this->mbinfo->setMbVolt($dev);
0 ignored issues
show
Documentation introduced by
$dev 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...
115
        }
116
    }
117
118
    /**
119
     * get the information
120
     *
121
     * @see PSI_Interface_Sensor::build()
122
     *
123
     * @return Void
124
     */
125
    public function build()
126
    {
127
        $this->_fans();
128
        $this->_temperature();
129
        $this->_voltage();
130
    }
131
}
132