XoopsModules25x/xoopsinfo

View on GitHub
phpsysinfo/plugins/ps/class.ps.inc.php

Summary

Maintainability
F
3 days
Test Coverage

Function __construct has a Cognitive Complexity of 108 (exceeds 5 allowed). Consider refactoring.
Open

    public function __construct($enc)
    {
        parent::__construct(__CLASS__, $enc);
        switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
        case 'command':
Severity: Minor
Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 2 days to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method __construct has 105 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function __construct($enc)
    {
        parent::__construct(__CLASS__, $enc);
        switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
        case 'command':
Severity: Major
Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 4 hrs to fix

    The class PS has an overall complexity of 61 which is very high. The configured complexity threshold is 50.
    Open

    class PS extends PSI_Plugin
    {
        /**
         * variable, which holds the content of the command
         * @var array

    Function execute has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        public function execute()
        {
            if (empty($this->_filecontent)) {
                return;
            }
    Severity: Minor
    Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _addchild has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        private function _addchild($child, SimpleXMLExtended $xml, &$positions)
        {
            foreach ($child as $key=>$value) {
                $xmlnode = $xml->addChild("Process");
                if (isset($value[0])) {
    Severity: Minor
    Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method execute has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function execute()
        {
            if (empty($this->_filecontent)) {
                return;
            }
    Severity: Minor
    Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 1 hr to fix

      Method _addchild has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function _addchild($child, SimpleXMLExtended $xml, &$positions)
          {
              foreach ($child as $key=>$value) {
                  $xmlnode = $xml->addChild("Process");
                  if (isset($value[0])) {
      Severity: Minor
      Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                        if ((PSI_OS !== 'WINNT') &&
                            ((($parentid === 1) && (!defined('PSI_PLUGIN_PS_SHOW_PID1CHILD_EXPANDED') || (PSI_PLUGIN_PS_SHOW_PID1CHILD_EXPANDED === false)))
                            || ((!defined('PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED') || (PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED === false)) && ($value[4] === "[kthreadd]")))) {
                            $xmlnode->addAttribute('Expanded', 0);
                        }
        Severity: Major
        Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                      for ($i = 0; $i < $total; $i++) {
                                          if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
          
                                              if (($totalmem != 0) && (preg_match('/^VmRSS:\s+(\d+)\s+kB/m', $buf, $tmppmem))) {
                                                  $pmem = round(100 * $tmppmem[1] / $totalmem, 1);
          Severity: Major
          Found in phpsysinfo/plugins/ps/class.ps.inc.php - About 45 mins to fix

            The method __construct() has 124 lines of code. Current threshold is set to 100. Avoid really long methods.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            The method __construct() has an NPath complexity of 831. The configured NPath complexity threshold is 200.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            NPathComplexity

            Since: 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example

            class Foo {
                function bar() {
                    // lots of complicated code
                }
            }

            Source https://phpmd.org/rules/codesize.html#npathcomplexity

            The method __construct() has a Cyclomatic Complexity of 33. The configured cyclomatic complexity threshold is 10.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            The method execute() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
            Open

                public function execute()
                {
                    if (empty($this->_filecontent)) {
                        return;
                    }

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            The method _addchild() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
            Open

                private function _addchild($child, SimpleXMLExtended $xml, &$positions)
                {
                    foreach ($child as $key=>$value) {
                        $xmlnode = $xml->addChild("Process");
                        if (isset($value[0])) {

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            Avoid using undefined variables such as '$namebuf' which will lead to PHP notices.
            Open

                                                if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i])-6)."cmdline", $namebuf, 0, 4096, false)) {

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

            Source https://phpmd.org/rules/cleancode.html#undefinedvariable

            Avoid using undefined variables such as '$namebuf' which will lead to PHP notices.
            Open

                                                    $name = str_replace(chr(0), ' ', trim($namebuf));

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

            Source https://phpmd.org/rules/cleancode.html#undefinedvariable

            Avoid using undefined variables such as '$mbuf' which will lead to PHP notices.
            Open

                                    $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

            Source https://phpmd.org/rules/cleancode.html#undefinedvariable

            Avoid using undefined variables such as '$mbuf' which will lead to PHP notices.
            Open

                                if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {

            UndefinedVariable

            Since: 2.8.0

            Detects when a variable is used that has not been defined before.

            Example

            class Foo
            {
                private function bar()
                {
                    // $message is undefined
                    echo $message;
                }
            }

            Source https://phpmd.org/rules/cleancode.html#undefinedvariable

            Missing class import via use statement (line '42', column '39').
            Open

                                $objLocator = new COM('WbemScripting.SWbemLocator');

            MissingImport

            Since: 2.7.0

            Importing all external classes in a file through use statements makes them clearly visible.

            Example

            function make() {
                return new \stdClass();
            }

            Source http://phpmd.org/rules/cleancode.html#MissingImport

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                            CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,pcpu,args", $buffer, PSI_DEBUG);

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                                $perf_wmi = CommonFunctions::getWMI($wmi, 'Win32_PerfFormattedData_PerfProc_Process', array('IDProcess', 'CreatingProcessID', 'PercentProcessorTime'));

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            The method execute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    } else {
                        $this->_result = array();
                    }

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                                $os_wmi = CommonFunctions::getWMI($wmi, 'Win32_OperatingSystem', array('TotalVisibleMemorySize'));

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                                    } else {
                                        $ps = trim($process['Caption']);
                                    }

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                                            if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                                if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                                                        } else {
                                                            $args = "[".$args."]";
                                                        }

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                        CommonFunctions::rfts(PSI_APP_ROOT."/data/ps.txt", $buffer);

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            Avoid assigning values to variables in if clauses and the like (line '99', column '57').
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            IfStatementAssignment

            Since: 2.7.0

            Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($foo = 'bar') { // possible typo
                        // ...
                    }
                    if ($baz = 0) { // always false
                        // ...
                    }
                }
            }

            Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                                $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'CommandLine', 'ProcessId', 'ParentProcessId', 'WorkingSetSize'));

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                                                } else {
                                                    $pmem = 0;
                                                }

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid using static access to class 'CommonFunctions' in method '__construct'.
            Open

                                                if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i])-6)."cmdline", $namebuf, 0, 4096, false)) {

            StaticAccess

            Since: 1.4.0

            Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

            Example

            class Foo
            {
                public function bar()
                {
                    Bar::baz();
                }
            }

            Source https://phpmd.org/rules/cleancode.html#staticaccess

            The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                        } else {
                            $this->_filecontent = array();
                        }

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid assigning values to variables in if clauses and the like (line '64', column '30').
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            IfStatementAssignment

            Since: 2.7.0

            Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($foo = 'bar') { // possible typo
                        // ...
                    }
                    if ($baz = 0) { // always false
                        // ...
                    }
                }
            }

            Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

            The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                        } else {
                            CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,pcpu,args", $buffer, PSI_DEBUG);
                            if (((PSI_OS == 'Linux') || (PSI_OS == 'Android')) && (!preg_match("/^[^\n]+\n\s*\d+\s+\d+\s+[\d\.]+\s+[\d\.]+\s+.+/", $buffer))) { //alternative method if no data
                                if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
                                    $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);

            ElseExpression

            Since: 1.4.0

            An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($flag) {
                        // one branch
                    } else {
                        // another branch
                    }
                }
            }

            Source https://phpmd.org/rules/cleancode.html#elseexpression

            Avoid using empty try-catch blocks in __construct.
            Open

                            } catch (Exception $e) {
                            }

            EmptyCatchBlock

            Since: 2.7.0

            Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

            Example

            class Foo {
            
              public function bar()
              {
                  try {
                      // ...
                  } catch (Exception $e) {} // empty catch block
              }
            }

            Source https://phpmd.org/rules/design.html#emptycatchblock

            Avoid unused local variables such as '$key'.
            Open

                    foreach ($child as $key=>$value) {

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

            TODO found
            Open

                                        //=> subtrees of processes may be missing (WHAT TODO?!?)

            Each class must be in a namespace of at least one level (a top-level vendor name)
            Open

            class PS extends PSI_Plugin

            Avoid classes with short names like PS. Configured minimum length is 3.
            Open

            class PS extends PSI_Plugin
            {
                /**
                 * variable, which holds the content of the command
                 * @var array

            ShortClassName

            Since: 2.9

            Detects when classes or interfaces have a very short name.

            Example

            class Fo {
            
            }
            
            interface Fo {
            
            }

            Source https://phpmd.org/rules/naming.html#shortclassname

            The property $_result is not named in camelCase.
            Open

            class PS extends PSI_Plugin
            {
                /**
                 * variable, which holds the content of the command
                 * @var array

            CamelCasePropertyName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name attributes.

            Example

            class ClassName {
                protected $property_name;
            }

            Source

            Avoid variables with short names like $ps. Configured minimum length is 3.
            Open

                                        $ps = trim($process['CommandLine']);

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            The property $_filecontent is not named in camelCase.
            Open

            class PS extends PSI_Plugin
            {
                /**
                 * variable, which holds the content of the command
                 * @var array

            CamelCasePropertyName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name attributes.

            Example

            class ClassName {
                protected $property_name;
            }

            Source

            Expected 1 space after "=>"; 0 found
            Open

                    foreach ($child as $key=>$value) {

            Method name "_addchild" should not be prefixed with an underscore to indicate visibility
            Open

                private function _addchild($child, SimpleXMLExtended $xml, &$positions)

            Property name "$_result" should not be prefixed with an underscore to indicate visibility
            Open

                private $_result = array();

            Terminating statement must be indented to the same level as the CASE body
            Open

                        break;

            Blank line found at end of control structure
            Open

            
            

            Expected 1 space after "=>"; 0 found
            Open

                        foreach ($row as $key=>$val) {

            Expected 1 space before "=>"; 0 found
            Open

                        foreach ($row as $key=>$val) {

            Terminating statement must be indented to the same level as the CASE body
            Open

                        break;

            Expected 1 space before "=>"; 0 found
            Open

                    foreach ($child as $key=>$value) {

            Terminating statement must be indented to the same level as the CASE body
            Open

                        break;

            Property name "$_filecontent" should not be prefixed with an underscore to indicate visibility
            Open

                private $_filecontent = array();

            Blank line found at start of control structure
            Open

                                            if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {

            Line exceeds 120 characters; contains 163 characters
            Open

                                || ((!defined('PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED') || (PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED === false)) && ($value[4] === "[kthreadd]")))) {

            Line exceeds 120 characters; contains 149 characters
            Open

                                                if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i])-6)."cmdline", $namebuf, 0, 4096, false)) {

            Line exceeds 120 characters; contains 133 characters
            Open

                                        //Unique identifier of the process that creates a process. Process identifier numbers are reused, so they

            Line exceeds 120 characters; contains 132 characters
            Open

             * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version

            Line exceeds 120 characters; contains 148 characters
            Open

                                ((($parentid === 1) && (!defined('PSI_PLUGIN_PS_SHOW_PID1CHILD_EXPANDED') || (PSI_PLUGIN_PS_SHOW_PID1CHILD_EXPANDED === false)))

            Line exceeds 120 characters; contains 126 characters
            Open

                                        //ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also

            Line exceeds 120 characters; contains 133 characters
            Open

                                        //only identify a process for the lifetime of that process. It is possible that the process identified by

            Line exceeds 120 characters; contains 133 characters
            Open

                                        //possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can

            Line exceeds 120 characters; contains 171 characters
            Open

                                $perf_wmi = CommonFunctions::getWMI($wmi, 'Win32_PerfFormattedData_PerfProc_Process', array('IDProcess', 'CreatingProcessID', 'PercentProcessorTime'));

            Line exceeds 120 characters; contains 181 characters
            Open

                                    $proccpu[trim($perf['IDProcess'])] = array('ParentProcessId'=>trim($perf['CreatingProcessID']), 'PercentProcessorTime'=>trim($perf['PercentProcessorTime']));

            Line exceeds 120 characters; contains 131 characters
            Open

                                        //use the CreationDate property to determine whether the specified parent was created after the process

            Line exceeds 120 characters; contains 165 characters
            Open

                                $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'CommandLine', 'ProcessId', 'ParentProcessId', 'WorkingSetSize'));

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    break;

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $perf_wmi = CommonFunctions::getWMI($wmi, 'Win32_PerfFormattedData_PerfProc_Process', array('IDProcess', 'CreatingProcessID', 'PercentProcessorTime'));

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    } else {

            Line indented incorrectly; expected at least 48 spaces, found 40
            Open

                                                    $buffer .= $pid." ".$ppid." ".$pmem." 0.0 ".$args."\n";

            Line indented incorrectly; expected 20 spaces, found 16
            Open

                            try {

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $objLocator = new COM('WbemScripting.SWbemLocator');

            Line indented incorrectly; expected 20 spaces, found 16
            Open

                            }

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    $buffer = "  PID  PPID %MEM %CPU COMMAND\n";

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $buf = "";

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                }

            Line indented incorrectly; expected 12 spaces, found 8
            Open

                    case 'data':

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                foreach ($perf_wmi as $perf) {

            Line indented incorrectly; expected at least 36 spaces, found 32
            Open

                                            break;

            Line indented incorrectly; expected 36 spaces, found 32
            Open

                                            if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                } else {

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    if (strlen(trim($process['CommandLine'])) > 0) {

            Line indented incorrectly; expected at least 40 spaces, found 36
            Open

                                                $name = null;

            Line indented incorrectly; expected at least 48 spaces, found 40
            Open

                                                    $ppid = $tmpppid[1];

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                }

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    $totalmem = 0;

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $process = array();

            Line indented incorrectly; expected 36 spaces, found 32
            Open

                                            }

            Line indented incorrectly; expected at least 16 spaces, found 12
            Open

                        $this->global_error->addConfigError("__construct()", "[ps] ACCESS");

            Line indented incorrectly; expected 16 spaces, found 12
            Open

                        if (PSI_OS == 'WINNT') {

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $proccpu = array();

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        if (isset($proccpu[$procid]) && ($proccpu[$procid]['ParentProcessId'] == $parentid)) {

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                if (preg_match('/^Pid:\s+(\d+)/m', $buf, $tmppid) &&

            Line indented incorrectly; expected 20 spaces, found 16
            Open

                            }

            Line indented incorrectly; expected 52 spaces, found 44
            Open

                                                        if ($name !== "") {

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    $proccpu[trim($perf['IDProcess'])] = array('ParentProcessId'=>trim($perf['CreatingProcessID']), 'PercentProcessorTime'=>trim($perf['PercentProcessorTime']));

            Line indented incorrectly; expected 52 spaces, found 44
            Open

                                                        } else {

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                foreach ($process_wmi as $process) {

            Line indented incorrectly; expected 48 spaces, found 40
            Open

                                                    }

            Line indented incorrectly; expected 12 spaces, found 8
            Open

                    case 'command':

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $ps = trim($process['CommandLine']);

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    }

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $parentid  = trim($process['ParentProcessId']);

            Line indented incorrectly; expected at least 36 spaces, found 32
            Open

                                            $cpu = $proccpu[$procid]['PercentProcessorTime'];

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        }

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $this->_filecontent[] = $procid." ".$parentid." ".$memusage." ".$cpu." ".$ps;

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                }

            Line indented incorrectly; expected 16 spaces, found 12
            Open

                        } else {

            Line indented incorrectly; expected at least 48 spaces, found 40
            Open

                                                    $args = $tmpargs[1];

            Line indented incorrectly; expected 16 spaces, found 12
            Open

                        }

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    if (is_array($processlist) && (($total = count($processlist)) > 0)) {

            Line indented incorrectly; expected at least 36 spaces, found 32
            Open

                                            $process[] = $processitem;

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        }

            Line indented incorrectly; expected at least 44 spaces, found 40
            Open

                                                    $pmem = 0;

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $wmi = $objLocator->ConnectServer('', 'root\CIMv2');

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $memtotal = 0;

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        }

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                foreach ($os_wmi as $os) {

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $memusage = round(trim($process['WorkingSetSize']) * 100 / $memtotal, 1);

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    }

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                }

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    $memtotal = $os['TotalVisibleMemorySize'] * 1024;

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'CommandLine', 'ProcessId', 'ParentProcessId', 'WorkingSetSize'));

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    if (($procid = trim($process['ProcessId'])) != 0) {

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $cpu = 0;

            Line indented incorrectly; expected at least 56 spaces, found 48
            Open

                                                            $args = "[".$args."]";

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        }

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    }

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                }

            Line indented incorrectly; expected at least 20 spaces, found 16
            Open

                            CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,pcpu,args", $buffer, PSI_DEBUG);

            Line indented incorrectly; expected at least 36 spaces, found 32
            Open

                                            $totalmem = $ar_buf[1];

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        natsort($processlist); //first sort

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        foreach ($processlist as $processitem) { //second sort

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i])-6)."cmdline", $namebuf, 0, 4096, false)) {

            Line indented incorrectly; expected at least 44 spaces, found 40
            Open

                                                    $name = str_replace(chr(0), ' ', trim($namebuf));

            Line indented incorrectly; expected at least 16 spaces, found 12
            Open

                        CommonFunctions::rfts(PSI_APP_ROOT."/data/ps.txt", $buffer);

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                }

            Line indented incorrectly; expected 20 spaces, found 16
            Open

                            if (((PSI_OS == 'Linux') || (PSI_OS == 'Android')) && (!preg_match("/^[^\n]+\n\s*\d+\s+\d+\s+[\d\.]+\s+[\d\.]+\s+.+/", $buffer))) { //alternative method if no data

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    }

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                if (($totalmem != 0) && (preg_match('/^VmRSS:\s+(\d+)\s+kB/m', $buf, $tmppmem))) {

            Line indented incorrectly; expected 48 spaces, found 40
            Open

                                                    if ($name !== null) {

            Line indented incorrectly; expected at least 56 spaces, found 48
            Open

                                                            $args = $name;

            Line indented incorrectly; expected at least 24 spaces, found 20
            Open

                                $os_wmi = CommonFunctions::getWMI($wmi, 'Win32_OperatingSystem', array('TotalVisibleMemorySize'));

            Line indented incorrectly; expected at least 32 spaces, found 28
            Open

                                        $ps = trim($process['Caption']);

            Line indented incorrectly; expected 20 spaces, found 16
            Open

                            } catch (Exception $e) {

            Line indented incorrectly; expected 24 spaces, found 20
            Open

                                if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {

            Line indented incorrectly; expected 28 spaces, found 24
            Open

                                    foreach ($bufe as $buf) {

            Line indented incorrectly; expected at least 28 spaces, found 24
            Open

                                    $processlist = glob('/proc/*/status', GLOB_NOSORT);

            Line indented incorrectly; expected 32 spaces, found 28
            Open

                                        for ($i = 0; $i < $total; $i++) {

            Line indented incorrectly; expected at least 44 spaces, found 40
            Open

                                                    $pmem = round(100 * $tmppmem[1] / $totalmem, 1);

            Line indented incorrectly; expected at least 48 spaces, found 40
            Open

                                                    $pid = $tmppid[1];

            Line indented incorrectly; expected 52 spaces, found 44
            Open

                                                        }

            Line indented incorrectly; expected 40 spaces, found 36
            Open

                                                }

            Line indented incorrectly; expected 12 spaces, found 8
            Open

                    default:

            The variable $os_wmi is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $process_wmi is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $process_wmi is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $ar_buf is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $ar_buf is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $perf_wmi is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $perf_wmi is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The variable $os_wmi is not named in camelCase.
            Open

                public function __construct($enc)
                {
                    parent::__construct(__CLASS__, $enc);
                    switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
                    case 'command':

            CamelCaseVariableName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name variables.

            Example

            class ClassName {
                public function doSomething() {
                    $data_module = new DataModule();
                }
            }

            Source

            The method _addchild is not named in camelCase.
            Open

                private function _addchild($child, SimpleXMLExtended $xml, &$positions)
                {
                    foreach ($child as $key=>$value) {
                        $xmlnode = $xml->addChild("Process");
                        if (isset($value[0])) {

            CamelCaseMethodName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name methods.

            Example

            class ClassName {
                public function get_name() {
                }
            }

            Source

            There are no issues that match your filters.

            Category
            Status