qcubed/framework

View on GitHub
includes/base_controls/QListItemManager.trait.php

Summary

Maintainability
A
1 hr
Test Coverage

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

        public function AddItemAt($intIndex, QListItemBase $objListItem) {
            try {
                $intIndex = QType::Cast($intIndex, QType::Integer);
            } catch (QInvalidCastException $objExc) {
                $objExc->IncrementOffset();
Severity: Minor
Found in includes/base_controls/QListItemManager.trait.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

Function AddListItems has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        public function AddListItems(array $objListItemArray) {
            try {
                $objListItemArray = QType::Cast($objListItemArray, QType::ArrayType);
                if ($objListItemArray) {
                    if (!reset($objListItemArray) instanceof QListItemBase) {
Severity: Minor
Found in includes/base_controls/QListItemManager.trait.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

Missing class import via use statement (line '68', column '15').
Open

                throw new QIndexOutOfRangeException($intIndex, "AddItemAt()");

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 '109', column '17').
Open

                        throw new QCallerException ('Not an array of QListItemBase types');

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 '144', column '15').
Open

                throw new QIndexOutOfRangeException($intIndex, "GetItem()");

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 '15').
Open

                throw new QIndexOutOfRangeException($intIndex, "RemoveItem()");

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

            } else {
                $this->objListItemArray = $objListItemArray;
            }

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 'QType' in method 'AddListItems'.
Open

                $objListItemArray = QType::Cast($objListItemArray, QType::ArrayType);

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 'QType' in method 'AddItemAt'.
Open

                $intIndex = QType::Cast($intIndex, QType::Integer);

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 'QType' in method 'RemoveItem'.
Open

                $intIndex = QType::Cast($intIndex, QType::Integer);

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 'QType' in method 'GetItem'.
Open

                $intIndex = QType::Cast($intIndex, QType::Integer);

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 'QType' in method 'ReplaceItem'.
Open

                $intIndex = QType::Cast($intIndex, QType::Integer);

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

            } else {
                throw new QIndexOutOfRangeException($intIndex, "AddItemAt()");
            }

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

        public function AddListItem(QListItemBase $objListItem) {
            if ($strControlId = $this->GetId()) {
                $num = 0;
                if ($this->objListItemArray) {
                    $num = count($this->objListItemArray);

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 variables with short names like $a. Configured minimum length is 3.
Open

            $a = explode ('_', $strId, 3);

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 method AddListItem is not named in camelCase.
Open

        public function AddListItem(QListItemBase $objListItem) {
            if ($strControlId = $this->GetId()) {
                $num = 0;
                if ($this->objListItemArray) {
                    $num = count($this->objListItemArray);

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

The method RemoveItem is not named in camelCase.
Open

        public function RemoveItem($intIndex) {
            try {
                $intIndex = QType::Cast($intIndex, QType::Integer);
            } catch (QInvalidCastException $objExc) {
                $objExc->IncrementOffset();

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

The method AddItemAt is not named in camelCase.
Open

        public function AddItemAt($intIndex, QListItemBase $objListItem) {
            try {
                $intIndex = QType::Cast($intIndex, QType::Integer);
            } catch (QInvalidCastException $objExc) {
                $objExc->IncrementOffset();

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

The method Reindex is not named in camelCase.
Open

        public function Reindex() {
            if ($this->GetId() && $this->objListItemArray) for ($i = 0; $i < $this->GetItemCount(); $i++) {
                $this->objListItemArray[$i]->SetId($this->GetId() . '_' . $i);    // assign the id based on parent id
                $this->objListItemArray[$i]->Reindex();
            }

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

The method GetItem is not named in camelCase.
Open

        public function GetItem($intIndex) {
            try {
                $intIndex = QType::Cast($intIndex, QType::Integer);
            } catch (QInvalidCastException $objExc) {
                $objExc->IncrementOffset();

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

The method GetItemCount is not named in camelCase.
Open

        public function GetItemCount() {
            $count = 0;
            if ($this->objListItemArray) {
                $count = count($this->objListItemArray);
            }

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

The method RemoveAllItems is not named in camelCase.
Open

        public function RemoveAllItems() {
            $this->MarkAsModified();
            $this->objListItemArray = null;
        }

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

The method ReplaceItem is not named in camelCase.
Open

        public function ReplaceItem($intIndex, QListItem $objListItem) {
            try {
                $intIndex = QType::Cast($intIndex, QType::Integer);
            } catch (QInvalidCastException $objExc) {
                $objExc->IncrementOffset();

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

The method FindItemByValue is not named in camelCase.
Open

        public function FindItemByValue($strValue) {
            if (!$this->objListItemArray) return null;
            foreach ($this->objListItemArray as $objItem) {
                if ($objItem->Value == $strValue) {
                    return $objItem;

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

The method MarkAsModified is not named in camelCase.
Open

        abstract public function MarkAsModified();

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

The method GetAllItems is not named in camelCase.
Open

        public function GetAllItems() {
            return $this->objListItemArray;
        }

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

The method GetId is not named in camelCase.
Open

        abstract public function GetId();

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

The method AddListItems is not named in camelCase.
Open

        public function AddListItems(array $objListItemArray) {
            try {
                $objListItemArray = QType::Cast($objListItemArray, QType::ArrayType);
                if ($objListItemArray) {
                    if (!reset($objListItemArray) instanceof QListItemBase) {

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

The method FindItem is not named in camelCase.
Open

        public function FindItem($strId) {
            if (!$this->objListItemArray) return null;
            $objFoundItem = null;
            $a = explode ('_', $strId, 3);
            if (isset($a[1]) &&

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