YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSEmployees/models/Record.php

Summary

Maintainability
A
35 mins
Test Coverage
F
0%

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

    public function getEmployeeHierarchy()
    {
        $focus = CRMEntity::getInstance($this->getModuleName());
        $hierarchy = $focus->getEmployeeHierarchy($this->getId());
        foreach ($hierarchy['entries'] as $employeeId => $employeeInfo) {
Severity: Minor
Found in modules/OSSEmployees/models/Record.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

Avoid using static access to class 'CRMEntity' in method 'getEmployeeHierarchy'.
Open

        $focus = CRMEntity::getInstance($this->getModuleName());

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

                } else {
                    $label = $name[2];
                }

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 'Vtiger_Record_Model' in method 'getEmployeeHierarchy'.
Open

                $recordModel = Vtiger_Record_Model::getCleanInstance('OSSEmployees');

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

Call to undeclared method \CRMEntity::getEmployeeHierarchy
Open

        $hierarchy = $focus->getEmployeeHierarchy($this->getId());
Severity: Critical
Found in modules/OSSEmployees/models/Record.php by phan

Saw unextractable annotation for comment '* @return <array>'</array>
Open

     * @return <Array>

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

class OSSEmployees_Record_Model extends Vtiger_Record_Model

The class OSSEmployees_Record_Model is not named in CamelCase.
Open

class OSSEmployees_Record_Model extends Vtiger_Record_Model
{
    /**
     * Function returns the details of Employees Hierarchy.
     *

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Spaces must be used to indent lines; tabs are not allowed
Open

        $hierarchy = $focus->getEmployeeHierarchy($this->getId());

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

                preg_match('/<a(.*)>(.*)<\\/a>/i', $employeeInfo[0], $name);

Spaces must be used to indent lines; tabs are not allowed
Open

                $recordModel->setId($employeeId);

Spaces must be used to indent lines; tabs are not allowed
Open

        return $hierarchy;

Spaces must be used to indent lines; tabs are not allowed
Open

                }

Line exceeds 120 characters; contains 147 characters
Open

                $hierarchy['entries'][$employeeId][0] = ($dashes[0] ?? '') . '<a href=' . $recordModel->getDetailViewUrl() . '>' . $label . '</a>';

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function returns the details of Employees Hierarchy.

Spaces must be used to indent lines; tabs are not allowed
Open

                    $label = $name[2];

Spaces must be used to indent lines; tabs are not allowed
Open

            if (null !== $matches) {

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return <Array>

Spaces must be used to indent lines; tabs are not allowed
Open

                $recordModel = Vtiger_Record_Model::getCleanInstance('OSSEmployees');

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

            preg_match('/<a href="+/', $employeeInfo[0], $matches);

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getEmployeeHierarchy()

Spaces must be used to indent lines; tabs are not allowed
Open

                preg_match('/[.\s]+/', $employeeInfo[0], $dashes);

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

                    $label = $employeeInfo[0];

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

                } else {

Spaces must be used to indent lines; tabs are not allowed
Open

                $hierarchy['entries'][$employeeId][0] = ($dashes[0] ?? '') . '<a href=' . $recordModel->getDetailViewUrl() . '>' . $label . '</a>';

Spaces must be used to indent lines; tabs are not allowed
Open

        $focus = CRMEntity::getInstance($this->getModuleName());

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach ($hierarchy['entries'] as $employeeId => $employeeInfo) {

Spaces must be used to indent lines; tabs are not allowed
Open

                if (empty($name[2])) {

Class name "OSSEmployees_Record_Model" is not in camel caps format
Open

class OSSEmployees_Record_Model extends Vtiger_Record_Model

There are no issues that match your filters.

Category
Status