PiTemp::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * pitemp sensor class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Sensor
9
 * @author    Marc Hillesheim <[email protected]>
10
 * @copyright 2012 Marc Hillesheim
11
 * @link      http://pi.no-ip.biz
12
 */
13
class PiTemp 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...
14
{
15
    private function _temperature()
16
    {
17
        $temp = null;
18
        $temp_max = null;
19
        if (!CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input', $temp, 0, 4096, false)) { // Not Banana Pi
20
            CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/temp', $temp);
21
            CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/trip_point_0_temp', $temp_max, 0, 4096, PSI_DEBUG);
22
        }
23
        if (!is_null($temp) && (trim($temp) != "")) {
24
            $dev = new SensorDevice();
25
            $dev->setName("CPU 1");
26
            $dev->setValue($temp / 1000);
27
            if (!is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) {
28
                $dev->setMax($temp_max / 1000);
29
            }
30
            $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...
31
        }
32
    }
33
34 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...
35
    {
36
        $volt = null;
37
        if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/voltage_now', $volt, 0, 4096, false) && !is_null($volt) && (trim($volt) != "")) { // Banana Pi
38
            $dev = new SensorDevice();
39
            $dev->setName("Voltage 1");
40
            $dev->setValue($volt / 1000000);
41
            $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...
42
        }
43
    }
44
45 View Code Duplication
    private function _current()
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...
46
    {
47
        $current = null;
48
        if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/current_now', $current, 0, 4096, false) && !is_null($current) && (trim($current) != "")) { // Banana Pi
49
            $dev = new SensorDevice();
50
            $dev->setName("Current 1");
51
            $dev->setValue($current / 1000000);
52
            $this->mbinfo->setMbCurrent($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...
53
        }
54
    }
55
56
    public function build()
57
    {
58
        $this->_temperature();
59
        $this->_voltage();
60
        $this->_current();
61
    }
62
}
63