_Linux::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
echo "<!DOCTYPE html>";
3
echo "<meta charset=\"UTF-8\">";
4
echo "<title> </title>";
5
echo "<body>";
6
7
define('APP_ROOT', dirname(__FILE__).'/..');
8
require_once APP_ROOT.'/includes/interface/class.PSI_Interface_OS.inc.php';
9
require_once APP_ROOT.'/includes/os/class.OS.inc.php';
10
require_once APP_ROOT.'/includes/to/class.System.inc.php';
11
require_once APP_ROOT.'/includes/os/class.Linux.inc.php';
12
define('PSI_USE_VHOST', false);
13
define('PSI_DEBUG', false);
14
define('PSI_LOAD_BAR', false);
15
16
$log_file = "";
17
$lsb = true; //enable detection lsb_release -a
18
$lsbfile = true; //enable detection /etc/lsb-release
19
20
class PSI_Error
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type PSI_Error has been defined more than once; this definition is ignored, only the first definition in phpsysinfo/includes/error/class.PSI_Error.inc.php (L26-290) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
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...
21
{
22
    public static function singleton()
23
    {
24
    }
25
}
26
27
class Parser
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Parser has been defined more than once; this definition is ignored, only the first definition in phpsysinfo/includes/class.Parser.inc.php (L26-271) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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
    public static function lspci()
30
    {
31
        return array();
32
    }
33
    public static function df()
34
    {
35
        return array();
36
    }
37
}
38
39
class CommonFunctions
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type CommonFunctions has been defined more than once; this definition is ignored, only the first definition in phpsysinfo/includes/class.CommonFunctions.inc.php (L26-563) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
40
{
41
    private static function _parse_log_file($string)
42
    {
43
        global $log_file;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
44
        if (file_exists($log_file)) {
45
            $contents = @file_get_contents($log_file);
46
            $contents = preg_replace("/\r\n/", "\n", $contents);
47 View Code Duplication
            if ($contents && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($string, '/')."\-\-\-\-\-\-\-\-\-\-\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
48
                $findIndex = $matches[0][1];
49
                if (preg_match("/\n/m", $contents, $matches, PREG_OFFSET_CAPTURE, $findIndex)) {
50
                    $startIndex = $matches[0][1]+1;
51
                    if (preg_match("/^\-\-\-\-\-\-\-\-\-\-/m", $contents, $matches, PREG_OFFSET_CAPTURE, $startIndex)) {
52
                        $stopIndex = $matches[0][1];
53
54
                        return substr($contents, $startIndex, $stopIndex-$startIndex);
55
                    } else {
56
                        return substr($contents, $startIndex);
57
                    }
58
                }
59
            }
60
        }
61
62
        return false;
63
    }
64
65
    public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
0 ignored issues
show
Unused Code introduced by
The parameter $intBytes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $booErrorRep is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        global $lsb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
68
        global $lsbfile;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
69
        if ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release")) {
70
            $strRet=self::_parse_log_file($strFileName);
71
            if ($strRet && ($intLines == 1) && (strpos($strRet, "\n") !== false)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $strRet of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
72
                $strRet=trim(substr($strRet, 0, strpos($strRet, "\n")));
73
            }
74
75
            return $strRet;
76
        } else {
77
            return false;
78
        }
79
    }
80
81
    public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true)
0 ignored issues
show
Unused Code introduced by
The parameter $strArgs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $booErrorRep is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        global $lsb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
84
        $strBuffer = '';
85
        if ($strProgramname=='lsb_release') {
86
            return $lsb && ($strBuffer = self::_parse_log_file('lsb_release -a'));
87
        } else {
88
            return $strBuffer = self::_parse_log_file($strProgramname);
89
        }
90
    }
91
92
    public static function fileexists($strFileName)
93
    {
94
        global $log_file;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
95
        global $lsb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
96
        global $lsbfile;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
97
        if (file_exists($log_file)
98
            && ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release"))
99
            && ($contents = @file_get_contents($log_file))
100
            && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($strFileName, '/')."\-\-\-\-\-\-\-\-\-\-\r?\n/m", $contents)) {
101
            return true;
102
        }
103
104
        return false;
105
    }
106
107
    public static function gdc()
108
    {
109
        return array();
110
    }
111
}
112
113
class _Linux extends Linux
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
114
{
115
    public function build()
116
    {
117
        parent::_distro();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (_distro() instead of build()). Are you sure this is correct? If so, you might want to change this to $this->_distro().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
118
    }
119
}
120
121
$system = new _Linux();
122
if ($handle = opendir(APP_ROOT.'/sample/distrotest')) {
123
    echo "<table cellpadding=\"2\" border=\"1\"  CELLSPACING=\"0\"";
124
    echo "<tr>";
125
    echo "<td>Distrotest sample</td>";
126
    echo "<td>Distro Name</td>";
127
    echo "<td>Distro Icon</td>";
128
    echo "<td>Distro Name (no lsb_release)</td>";
129
    echo "<td>Distro Icon (no lsb_release)</td>";
130
    echo "<td>Distro Name (no lsb_release and no /etc/lsb-release)</td>";
131
    echo "<td>Distro Icon (no lsb_release and no /etc/lsb-release)</td>";
132
    echo "</tr>";
133
    while (false !== ($entry = readdir($handle))) {
134
        if (($entry!=".")&&($entry!="..")) {
135
            if ($shandle = opendir(APP_ROOT."/sample/distrotest/$entry")) {
136
                while (false !== ($sentry = readdir($shandle))) {
137
                    if (($sentry!=".")&&($sentry!="..")) {
138
                        $log_file=APP_ROOT.'/sample/distrotest/'.$entry.'/'.$sentry;
139
                        echo "<tr>";
140
                        echo "<td>".$entry.'/'.$sentry."</td>";
141
142
                        $lsb = true;
143
                        $lsbfile = true;
144
                        $sys=$system->getSys();
145
                        $distro=$sys->getDistribution();
146
                        $icon=$sys->getDistributionIcon();
147
                        if ($icon == '') $icon="unknown.png";
148
                        if ($icon != $entry.'.png')
149
                            echo "<td style='color:red'>";
150
                        else
151
                            echo "<td>";
152
                        echo $distro."</td>";
153
                        if ($icon != $entry.'.png')
154
                            echo "<td style='color:red'>";
155
                        else
156
                            echo "<td>";
157
                        echo "<img src=\"../gfx/images/".$icon."\" height=\"16\" width=\"16\">";
158
                        echo $icon."</td>";
159
                        $sys->setDistribution("");
160
                        $sys->setDistributionIcon("");
161
162
                        $lsb = false;
163
                        $lsbfile = true;
164
                        $sys=$system->getSys();
165
                        $distro=$sys->getDistribution();
166
                        $icon=$sys->getDistributionIcon();
167
                        if ($icon == '') $icon="unknown.png";
168
                        if ($icon != $entry.'.png')
169
                            echo "<td style='color:red'>";
170
                        else
171
                            echo "<td>";
172
                        echo $distro."</td>";
173
                        if ($icon != $entry.'.png')
174
                            echo "<td style='color:red'>";
175
                        else
176
                            echo "<td>";
177
                        echo "<img src=\"../gfx/images/".$icon."\" height=\"16\" width=\"16\">";
178
                        echo $icon."</td>";
179
                        $sys->setDistribution("");
180
                        $sys->setDistributionIcon("");
181
182
                        $lsb = false;
183
                        $lsbfile = false;
184
                        $sys=$system->getSys();
185
                        $distro=$sys->getDistribution();
186
                        $icon=$sys->getDistributionIcon();
187
                        if ($icon == '') $icon="unknown.png";
188
                        if ($icon != $entry.'.png')
189
                            echo "<td style='color:red'>";
190
                        else
191
                            echo "<td>";
192
                        echo $distro."</td>";
193
                        if ($icon != $entry.'.png')
194
                            echo "<td style='color:red'>";
195
                        else
196
                            echo "<td>";
197
                        echo "<img src=\"../gfx/images/".$icon."\" height=\"16\" width=\"16\">";
198
                        echo $icon."</td>";
199
                        $sys->setDistribution("");
200
                        $sys->setDistributionIcon("");
201
202
                        echo "</tr>";
203
                    }
204
                }
205
                closedir($shandle);
206
            }
207
        }
208
    }
209
    echo "</table>";
210
    closedir($handle);
211
}
212
echo "</body>";
213