mambax7/publisher

View on GitHub
class/Category.php

Summary

Maintainability
A
1 hr
Test Coverage

checkPermission accesses the super-global variable $GLOBALS.
Open

    public function checkPermission()
    {
        $ret = false;
        if (Utility::userIsAdmin()) {
            return true;
Severity: Minor
Found in class/Category.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

checkPermission accesses the super-global variable $GLOBALS.
Open

    public function checkPermission()
    {
        $ret = false;
        if (Utility::userIsAdmin()) {
            return true;
Severity: Minor
Found in class/Category.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

The class Category has 16 fields. Consider redesigning Category to keep the number of fields under 15.
Open

class Category extends \XoopsObject
{
    /**
     * @var Helper
     */
Severity: Minor
Found in class/Category.php by phpmd

TooManyFields

Since: 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example

class Person {
   protected $one;
   private $two;
   private $three;
   [... many more fields ...]
}

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

Function getCategoryPath has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function getCategoryPath($withAllLink = true)
    {
        if (empty($this->categoryPath)) {
            if ($withAllLink) {
                $ret = $this->getCategoryLink();
Severity: Minor
Found in class/Category.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

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

    public function store($sendNotifications = true, $force = true)
Severity: Minor
Found in class/Category.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 '204', column '31').
Open

                    throw new \RuntimeException('NOT LOADED');
Severity: Minor
Found in class/Category.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 getCategoryLink has a boolean flag argument $class, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getCategoryLink($class = false)
Severity: Minor
Found in class/Category.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 getCategoryPath has a boolean flag argument $withAllLink, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getCategoryPath($withAllLink = true)
Severity: Minor
Found in class/Category.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 store has a boolean flag argument $sendNotifications, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function store($sendNotifications = true, $force = true)
Severity: Minor
Found in class/Category.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 '172', column '35').
Open

                        throw new \RuntimeException(_NOPERM);
Severity: Minor
Found in class/Category.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 toArrayTable uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $category['image_path'] = '';
        }
Severity: Minor
Found in class/Category.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\Publisher\Seo' in method 'getCategoryUrl'.
Open

        return Seo::generateUrl('category', $this->categoryid(), $this->short_url());
Severity: Minor
Found in class/Category.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 'XoopsModules\Publisher\Utility' in method 'checkPermission'.
Open

        if (Utility::userIsAdmin()) {
Severity: Minor
Found in class/Category.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 'XoopsModules\Publisher\Helper' in method '__construct'.
Open

        $this->helper = Helper::getInstance();
Severity: Minor
Found in class/Category.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 'XoopsModules\Publisher\Utility' in method 'toArraySimple'.
Open

            $category['image_path'] = Utility::getImageDir('category', false) . $this->getImage();
Severity: Minor
Found in class/Category.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 getCategoryPath uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $ret = $this->name();
            }
Severity: Minor
Found in class/Category.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 toArraySimple uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $category['image_path'] = '';
        }
Severity: Minor
Found in class/Category.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\Publisher\Utility' in method 'toArrayTable'.
Open

            $category['image_path'] = Utility::getImageDir('category', false) . $this->getImage();
Severity: Minor
Found in class/Category.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 property $meta_keywords is not named in camelCase.
Open

class Category extends \XoopsObject
{
    /**
     * @var Helper
     */
Severity: Minor
Found in class/Category.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The property $meta_description is not named in camelCase.
Open

class Category extends \XoopsObject
{
    /**
     * @var Helper
     */
Severity: Minor
Found in class/Category.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The property $short_url is not named in camelCase.
Open

class Category extends \XoopsObject
{
    /**
     * @var Helper
     */
Severity: Minor
Found in class/Category.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

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

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

There are no issues that match your filters.

Category
Status