XoopsModules25x/xoopspoll

View on GitHub
class/LogHandler.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method hasVoted has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function hasVoted(?int $pid, string $ip, int $uid = 0): bool
    {
        $uid        = (int)$uid;
        $pid        = (int)$pid;
        $voted      = true;
Severity: Minor
Found in class/LogHandler.php - About 1 hr to fix

    Function hasVoted has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public function hasVoted(?int $pid, string $ip, int $uid = 0): bool
        {
            $uid        = (int)$uid;
            $pid        = (int)$pid;
            $voted      = true;
    Severity: Minor
    Found in class/LogHandler.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

    Missing class import via use statement (line '67', column '25').
    Open

            $criteria = new \Criteria('option_id', $option_id, '=');
    Severity: Minor
    Found in class/LogHandler.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 '147', column '25').
    Open

            $criteria = new \Criteria('option_id', (int)$option_id, '=');
    Severity: Minor
    Found in class/LogHandler.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 '187', column '36').
    Open

                    $criteria->add(new \Criteria('user_id', 0, '='));
    Severity: Minor
    Found in class/LogHandler.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 '173', column '32').
    Open

                $criteria->add(new \Criteria('poll_id', $pid, '='));
    Severity: Minor
    Found in class/LogHandler.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 '180', column '36').
    Open

                    $criteria->add(new \Criteria('user_id', $uid, '='));
    Severity: Minor
    Found in class/LogHandler.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 '185', column '36').
    Open

                    $criteria->add(new \Criteria('ip', $ip, '='));
    Severity: Minor
    Found in class/LogHandler.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 '129', column '25').
    Open

            $criteria = new \CriteriaCompo();
    Severity: Minor
    Found in class/LogHandler.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 '130', column '28').
    Open

            $criteria->add(new \Criteria('poll_id', (int)$pid, '='));
    Severity: Minor
    Found in class/LogHandler.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 '172', column '34').
    Open

                $criteria      = new \CriteriaCompo();
    Severity: Minor
    Found in class/LogHandler.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 '115', column '25').
    Open

            $criteria = new \Criteria('poll_id', (int)$pid, '=');
    Severity: Minor
    Found in class/LogHandler.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 '193', column '37').
    Open

                        $criteria = new \CriteriaCompo();
    Severity: Minor
    Found in class/LogHandler.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 '195', column '40').
    Open

                        $criteria->add(new \Criteria('time', (int)$pollStarttime, '>='));
    Severity: Minor
    Found in class/LogHandler.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 '81', column '25').
    Open

            $criteria = new \Criteria('poll_id', (int)$pid, '=');
    Severity: Minor
    Found in class/LogHandler.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 '99', column '28').
    Open

            $criteria->add(new \Criteria('poll_id', (int)$pid, '='));
    Severity: Minor
    Found in class/LogHandler.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 '181', column '36').
    Open

                    $criteria->add(new \Criteria('time', (int)$pollStarttime, '>='));
    Severity: Minor
    Found in class/LogHandler.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 '194', column '40').
    Open

                        $criteria->add(new \Criteria('poll_id', $pid, '='));
    Severity: Minor
    Found in class/LogHandler.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 '98', column '25').
    Open

            $criteria = new \CriteriaCompo();
    Severity: Minor
    Found in class/LogHandler.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 '186', column '36').
    Open

                    $criteria->add(new \Criteria('time', (int)$pollStarttime, '>='));
    Severity: Minor
    Found in class/LogHandler.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 hasVoted uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $voted = false;
                    }
    Severity: Minor
    Found in class/LogHandler.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 hasVoted uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    /* Check cookie to see if someone from this system has voted before */
                    if (\array_key_exists($pid, $votedPolls) && ((int)$votedPolls[$pid] >= $pollStarttime)) {
                        $criteria = new \CriteriaCompo();
                        $criteria->add(new \Criteria('poll_id', $pid, '='));
    Severity: Minor
    Found in class/LogHandler.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 '\XoopsModules\Xoopspoll\Utility' in method 'hasVoted'.
    Open

            $votedPolls = Utility::getVoteCookie();
    Severity: Minor
    Found in class/LogHandler.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 unused parameters such as '$helper'.
    Open

        public function __construct(\XoopsDatabase $db = null, $helper = null)
    Severity: Minor
    Found in class/LogHandler.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

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

    HACK found
    Open

            //        $votedPolls = [];  //TESTING HACK TO BYPASS COOKIES
    Severity: Minor
    Found in class/LogHandler.php by fixme

    TODO found
    Open

            //TODO Parameter '$voterGrps' type is not compatible with declaration
    Severity: Minor
    Found in class/LogHandler.php by fixme

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

        public function __construct(\XoopsDatabase $db = null, $helper = null)
    Severity: Minor
    Found in class/LogHandler.php by phpmd

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

        public function getTotalVotesByOptionId(int $option_id): int
        {
            $criteria = new \Criteria('option_id', (int)$option_id, '=');
            $votes    = $this->getCount($criteria);
    
    
    Severity: Minor
    Found in class/LogHandler.php by phpmd

    CamelCaseParameterName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething($user_name) {
        }
    }

    Source

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

        public function hasVoted(?int $pid, string $ip, int $uid = 0): bool
    Severity: Minor
    Found in class/LogHandler.php by phpmd

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

        public function deleteByOptionId(int $option_id): bool
        {
            $criteria = new \Criteria('option_id', $option_id, '=');
            $success  = $this->deleteAll($criteria);
    
    
    Severity: Minor
    Found in class/LogHandler.php by phpmd

    CamelCaseParameterName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething($user_name) {
        }
    }

    Source

    There must be one USE keyword per declaration
    Open

    use XoopsModules\Xoopspoll\{
    Severity: Minor
    Found in class/LogHandler.php by phpcodesniffer

    The variable $option_id is not named in camelCase.
    Open

        public function deleteByOptionId(int $option_id): bool
        {
            $criteria = new \Criteria('option_id', $option_id, '=');
            $success  = $this->deleteAll($criteria);
    
    
    Severity: Minor
    Found in class/LogHandler.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 $option_id is not named in camelCase.
    Open

        public function getTotalVotesByOptionId(int $option_id): int
        {
            $criteria = new \Criteria('option_id', (int)$option_id, '=');
            $votes    = $this->getCount($criteria);
    
    
    Severity: Minor
    Found in class/LogHandler.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