mambax7/publisher

View on GitHub
class/FormDateTime.php

Summary

Maintainability
A
1 hr
Test Coverage

__construct accesses the super-global variable $GLOBALS.
Open

    public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
    {
        parent::__construct($caption, ' ');
        $value = (int)$value;
        $value = ($value > 0) ? $value : \time();
Severity: Minor
Found in class/FormDateTime.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

__construct accesses the super-global variable $GLOBALS.
Open

    public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
    {
        parent::__construct($caption, ' ');
        $value = (int)$value;
        $value = ($value > 0) ? $value : \time();
Severity: Minor
Found in class/FormDateTime.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
Severity: Minor
Found in class/FormDateTime.php - About 45 mins to fix

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

        public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
        {
            parent::__construct($caption, ' ');
            $value = (int)$value;
            $value = ($value > 0) ? $value : \time();
    Severity: Minor
    Found in class/FormDateTime.php - About 35 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

    Missing class import via use statement (line '52', column '31').
    Open

            $this->addElement(new \XoopsFormTextDateSelect('', $name . '[date]', $size, $value));
    Severity: Minor
    Found in class/FormDateTime.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 __construct has a boolean flag argument $formatTimestamp, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
    Severity: Minor
    Found in class/FormDateTime.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 '61', column '27').
    Open

            $timeselect = new \XoopsFormSelect('', $name . '[time]', $datetime['hours'] * 3600 + 600 * \floor($datetime['minutes'] / 10));
    Severity: Minor
    Found in class/FormDateTime.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 __construct has a boolean flag argument $showtime, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
    Severity: Minor
    Found in class/FormDateTime.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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $timeoffset = null;
                }
    Severity: Minor
    Found in class/FormDateTime.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 unused parameters such as '$showtime'.
    Open

        public function __construct($caption, $name, $size = 15, $value = 0, $showtime = true, $formatTimestamp = true)
    Severity: Minor
    Found in class/FormDateTime.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

    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 27 and the first side effect is on line 22.
    Open

    <?php declare(strict_types=1);
    Severity: Minor
    Found in class/FormDateTime.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status