YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Groups/models/Member.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
23%

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

    public static function getAll($onlyActive = true)

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 '74', column '18').
Open

            $query = (new App\Db\Query())

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 '75', column '31').
Open

                ->select(['member' => new \yii\db\Expression("CONCAT('{$type}',':',{$tableName}.{$index})")])

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 '103', column '24').
Open

                $recordModel = new Settings_Roles_Record_Model();

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 '108', column '24').
Open

                $recordModel = new Settings_Groups_Record_Model();

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

Avoid using static access to class 'Users_Record_Model' in method 'getDetailViewUrl'.
Open

                $recordModel = Users_Record_Model::getCleanInstance($type);

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 'Settings_Roles_Record_Model' in method 'getAll'.
Open

        $allRoles = Settings_Roles_Record_Model::getAll();

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

            } else {
                $queryAll = $query;
            }

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 'Users_Record_Model' in method 'getAll'.
Open

        $allUsers = Users_Record_Model::getAll($onlyActive);

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 'Settings_Groups_Record_Model' in method 'getAll'.
Open

        $allGroups = Settings_Groups_Record_Model::getAll();

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

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

     * @return <Number> Id

Argument 1 (value) is string but \Users_Record_Model::setId() takes int defined at /code/modules/Vtiger/models/Record.php:67
Open

                $recordModel->setId($recordId);

Argument 1 (id) is string but \Settings_Groups_Record_Model::setId() takes int defined at /code/modules/Settings/Groups/models/Record.php:37
Open

                $recordModel->setId($recordId);

Call to undeclared method \App\Db\Query::select
Open

            $query = (new App\Db\Query())
Severity: Critical
Found in modules/Settings/Groups/models/Member.php by phan

Call to method __construct from undeclared class \yii\db\Expression
Open

                ->select(['member' => new \yii\db\Expression("CONCAT('{$type}',':',{$tableName}.{$index})")])
Severity: Critical
Found in modules/Settings/Groups/models/Member.php by phan

Saw unextractable annotation for comment '* @return <array> - Array of Settings_Groups_Record_Model instances'</array>
Open

     * @return <Array> - Array of Settings_Groups_Record_Model instances

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        foreach ($allRoles as $roleId => $roleModel) {
            $qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_ROLES, $roleId);
            $member = new self();
            $members[self::MEMBER_TYPE_ROLES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());

Severity: Major
Found in modules/Settings/Groups/models/Member.php and 1 other location - About 3 hrs to fix
modules/Settings/SharingAccess/models/RuleMember.php on lines 117..125

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 148.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

class Settings_Groups_Member_Model extends \App\Base

The class Settings_Groups_Member_Model is not named in CamelCase.
Open

class Settings_Groups_Member_Model extends \App\Base
{
    const MEMBER_TYPE_USERS = 'Users';
    const MEMBER_TYPE_GROUPS = 'Groups';
    const MEMBER_TYPE_ROLES = 'Roles';

CamelCaseClassName

Since: 0.2

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

Example

class class_name {
}

Source

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

    public static function getQualifiedId($type, $id)

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

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

    public static function getIdComponentsFromQualifiedId($id)

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

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

    }

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

            [$tableName, $index] = $indexes;

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

     * return string url.

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

                $recordModel->set('roleid', $recordId);

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

        return explode(':', $id);

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

    /**

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

            self::MEMBER_TYPE_ROLES => ['vtiger_group2role', 'roleid'],

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

                $queryAll = $query;

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

     * @return <Array> - Array of Settings_Groups_Record_Model instances

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

    const MEMBER_TYPE_GROUPS = 'Groups';

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

    /**

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

     * @param int         $groupId

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

        [$type, $recordId] = self::getIdComponentsFromQualifiedId($this->getId());

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

                $recordModel = new Settings_Roles_Record_Model();

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

                return $recordModel->getEditViewUrl();

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

    const MEMBER_TYPE_ROLE_AND_SUBORDINATES = 'RoleAndSubordinates';

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

        foreach ($tables as $type => $indexes) {

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

                $queryAll->union($query, true);

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

        return $queryAll ? $queryAll->column() : [];

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

    public function getDetailViewUrl()

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

            case 'Groups':

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

    {

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

     *

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

            self::MEMBER_TYPE_USERS => ['vtiger_users2group', 'userid'],

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

            self::MEMBER_TYPE_GROUPS => ['vtiger_group2grouprel', 'containsgroupid'],

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

                ->where(["{$tableName}.groupid" => $groupId]);

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

            if ($queryAll) {

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

    public static function getIdComponentsFromQualifiedId($id)

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

        if (null !== $type) {

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

        $queryAll = null;

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

     * Function to get the Group Name.

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

        return $type . ':' . $id;

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

                ->select(['member' => new \yii\db\Expression("CONCAT('{$type}',':',{$tableName}.{$index})")])

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

    }

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

                $recordModel->setId($recordId);

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

            case 'Roles':

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

        }

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

            $tables = isset($tables[$type]) ? [$type => $tables[$type]] : [];

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

        }

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

            case 'Users':

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

        foreach ($allRoles as $roleId => $roleModel) {

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

            $members[self::MEMBER_TYPE_ROLE_AND_SUBORDINATES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());

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

    public static function getQualifiedId($type, $id)

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

    /**

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

            default:

Line exceeds 120 characters; contains 131 characters
Open

            $members[self::MEMBER_TYPE_USERS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $userModel->getName());

Line exceeds 120 characters; contains 133 characters
Open

            $members[self::MEMBER_TYPE_GROUPS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $groupModel->getName());

Line exceeds 120 characters; contains 131 characters
Open

            $members[self::MEMBER_TYPE_ROLES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());

Line exceeds 120 characters; contains 147 characters
Open

            $members[self::MEMBER_TYPE_ROLE_AND_SUBORDINATES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());

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

        }

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

        return $this->get('id');

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

                return $recordModel->getDetailViewUrl();

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

            case 'RoleAndSubordinates':

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

                $recordModel->setId($recordId);

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

     *

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

    const MEMBER_TYPE_ROLES = 'Roles';

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

     * @return <Number> Id

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

     * Gets members by type.

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

    public static function getAllByTypeForGroup(int $groupId, ?string $type = null): array

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

     * Function to get Detail View Url of this member

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

                $recordModel = Users_Record_Model::getCleanInstance($type);

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

                return $recordModel->getDetailViewUrl();

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

            $members[self::MEMBER_TYPE_USERS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $userModel->getName());

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

    }

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

        $tables = [

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

                ->from($tableName)

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

    {

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

        switch ($type) {

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

     *

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

            $qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_GROUPS, $groupId);

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

            $member = new self();

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

     * Function to get the Qualified Id of the Group Member.

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

     */

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

    public function getId()

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

        return $this->get('name');

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

     * @param mixed $onlyActive

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

    public static function getAll($onlyActive = true)

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

        $allUsers = Users_Record_Model::getAll($onlyActive);

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

    const MEMBER_TYPE_USERS = 'Users';

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

    public function getName()

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

    {

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

            self::MEMBER_TYPE_ROLE_AND_SUBORDINATES => ['vtiger_group2rs', 'roleandsubid']

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

            $query = (new App\Db\Query())

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

     */

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

                $recordModel = new Settings_Groups_Record_Model();

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

     * Function to get all the groups.

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

        }

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

        $allRoles = Settings_Roles_Record_Model::getAll();

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

        $members = [];

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

            $qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_ROLE_AND_SUBORDINATES, $roleId);

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

        foreach ($allUsers as $userId => $userModel) {

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

            $members[self::MEMBER_TYPE_ROLES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());

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

        return $members;

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

     * @return string

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

     * @param string|null $type

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

        }

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

                break;

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

        }

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

            $qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_ROLES, $roleId);

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

            $qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_USERS, $userId);

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

            $member = new self();

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

            $member = new self();

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

        $allGroups = Settings_Groups_Record_Model::getAll();

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

        foreach ($allGroups as $groupId => $groupModel) {

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

    {

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

            $member = new self();

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

            $members[self::MEMBER_TYPE_GROUPS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $groupModel->getName());

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

class Settings_Groups_Member_Model extends \App\Base

There are no issues that match your filters.

Category
Status