XoopsModules25x/userlog

View on GitHub
class/helper.php

Summary

Maintainability
A
1 hr
Test Coverage

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

class Userlog extends \Xmf\Module\Helper
{
    public $logmodule;
    public $user;
    public $debugArray   = [];
Severity: Minor
Found in class/helper.php by phpmd

Function patchLoginHistory has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function patchLoginHistory($post = null, $uid = 0, $unsetPass = true)
    {
        if ($uid > 0 || empty($post['pass']) || empty($post['uname'])) {
            return $post;
        }
Severity: Minor
Found in class/helper.php - About 1 hr 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 getModules has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getModules($dirnames = [], $otherCriteria = null, $asObj = false)
    {
        // get all dirnames
        /** @var XoopsModuleHandler $moduleHandler */
        $moduleHandler = xoops_getHandler('module');
Severity: Minor
Found in class/helper.php - About 25 mins 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

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

            $dirNames[$module->dirname()] = $module->name();
Severity: Minor
Found in class/helper.php by phpmd

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 '$dirNames' which will lead to PHP notices.
Open

        return $dirNames;
Severity: Minor
Found in class/helper.php by phpmd

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 '$dirNames' which will lead to PHP notices.
Open

        $dirNames['system-root'] = _YOURHOME;
Severity: Minor
Found in class/helper.php by phpmd

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 '93', column '30').
Open

        $criteria      = new CriteriaCompo();
Severity: Minor
Found in class/helper.php by phpmd

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

Missing class import via use statement (line '96', column '36').
Open

                $criteria->add(new Criteria('dirname', $mDir), 'OR');
Severity: Minor
Found in class/helper.php by phpmd

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

The method getModules has a boolean flag argument $asObj, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getModules($dirnames = [], $otherCriteria = null, $asObj = false)
Severity: Minor
Found in class/helper.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

Missing class import via use statement (line '102', column '28').
Open

        $criteria->add(new Criteria('isactive', 1), 'AND');
Severity: Minor
Found in class/helper.php by phpmd

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

The method patchLoginHistory has a boolean flag argument $unsetPass, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function patchLoginHistory($post = null, $uid = 0, $unsetPass = true)
Severity: Minor
Found in class/helper.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

The method getInstance has a boolean flag argument $debug, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function getInstance($debug = false)
Severity: Minor
Found in class/helper.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

Avoid using static access to class 'XoopsLocale' in method 'formatTime'.
Open

        return class_exists('XoopsLocal') ? XoopsLocal::formatTimestamp($intTime, $dateFormat, $timeoffset) : XoopsLocale::formatTimestamp($intTime, $dateFormat, $timeoffset); // use XoopsLocale in xoops26
Severity: Minor
Found in class/helper.php by phpmd

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 'XoopsFile' in method 'initBrowsCap'.
Open

        $folderHandler = XoopsFile::getHandler('folder', $browscapCache, true);
Severity: Minor
Found in class/helper.php by phpmd

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 'XoopsFile' in method 'getAllLogFiles'.
Open

            $folderHandler                           = XoopsFile::getHandler('folder', $path . '/' . USERLOG_DIRNAME);
Severity: Minor
Found in class/helper.php by phpmd

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 '310', column '22').
Open

    public function patchLoginHistory($post = null, $uid = 0, $unsetPass = true)
    {
        if ($uid > 0 || empty($post['pass']) || empty($post['uname'])) {
            return $post;
        }
Severity: Minor
Found in class/helper.php by phpmd

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 '\Xmf\Request' in method 'getCookie'.
Open

        $toggles = Request::getString($this->cookiePrefix . $name, null, 'cookie');
Severity: Minor
Found in class/helper.php by phpmd

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 initLogModule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $hModule         = xoops_getHandler('module');
            $this->logmodule = $hModule->getByDirname('system');
            $this->logmodule->setVar('dirname', 'system-root');
        }
Severity: Minor
Found in class/helper.php by phpmd

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

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

        } else {
            $this->user = null;
        }
Severity: Minor
Found in class/helper.php by phpmd

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 'XoopsLocal' in method 'formatTime'.
Open

        return class_exists('XoopsLocal') ? XoopsLocal::formatTimestamp($intTime, $dateFormat, $timeoffset) : XoopsLocale::formatTimestamp($intTime, $dateFormat, $timeoffset); // use XoopsLocale in xoops26
Severity: Minor
Found in class/helper.php by phpmd

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 '313', column '22').
Open

    public function patchLoginHistory($post = null, $uid = 0, $unsetPass = true)
    {
        if ($uid > 0 || empty($post['pass']) || empty($post['uname'])) {
            return $post;
        }
Severity: Minor
Found in class/helper.php by phpmd

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 unused local variables such as '$currentPath'.
Open

        $currentPath = $this->getConfig('logfilepath');
Severity: Minor
Found in class/helper.php by phpmd

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

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

class Userlog extends \Xmf\Module\Helper
Severity: Minor
Found in class/helper.php by phpcodesniffer

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 34 and the first side effect is on line 25.
Open

<?php
Severity: Minor
Found in class/helper.php by phpcodesniffer

Line exceeds 120 characters; contains 139 characters
Open

        $loginSuccess  = $memberHandler->loginUser($post['uname'], $post['pass']); // check login to find if this user is exist in database
Severity: Minor
Found in class/helper.php by phpcodesniffer

The variable $last_visit is not named in camelCase.
Open

    public function patchLoginHistory($post = null, $uid = 0, $unsetPass = true)
    {
        if ($uid > 0 || empty($post['pass']) || empty($post['uname'])) {
            return $post;
        }
Severity: Minor
Found in class/helper.php by phpmd

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 $last_visit is not named in camelCase.
Open

    public function patchLoginHistory($post = null, $uid = 0, $unsetPass = true)
    {
        if ($uid > 0 || empty($post['pass']) || empty($post['uname'])) {
            return $post;
        }
Severity: Minor
Found in class/helper.php by phpmd

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

There are no issues that match your filters.

Category
Status