YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/WebserviceApps/models/Record.php

Summary

Maintainability
A
0 mins
Test Coverage
B
85%

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

        return (new App\Db\Query())->from('w_#__servers')->where($where)->exists();

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

            throw new \App\Exceptions\IllegalValue('ERR_DUPLICATE_LOGIN', 406);

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 assigning values to variables in if clauses and the like (line '64', column '7').
Open

    public static function getInstanceById($recordId)
    {
        if (empty($recordId)) {
            return false;
        }

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 using static access to class '\App\Cache' in method 'save'.
Open

        \App\Cache::delete('App\Fields\ServerAccess::get', $this->getId());

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 '\App\Cache' in method 'delete'.
Open

        \App\Cache::delete('App\Fields\ServerAccess::get', $this->getId());

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

        } else {
            $db->createCommand()->update('w_#__servers', $data, ['id' => $this->getId()])->execute();
        }

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 '\App\Fields\ServerAccess' in method 'getInstanceById'.
Open

        if ($data = \App\Fields\ServerAccess::get($recordId)) {

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 '\App\Encryption' in method 'save'.
Open

            $data['api_key'] = App\Encryption::getInstance()->encrypt(\App\Encryption::generatePassword(self::KEY_LENGTH));

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 '\App\Db' in method 'save'.
Open

        $db = \App\Db::getInstance('webservice');

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

Define a constant instead of duplicating this literal "w_#__servers" 4 times.
Open

            ->delete('w_#__servers', ['id' => $this->getId()])

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Argument 2 (key) is int but \App\Cache::delete() takes string defined at /code/app/Cache.php:105
Open

        \App\Cache::delete('App\Fields\ServerAccess::get', $this->getId());

Call to method getInstance from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

            $data['api_key'] = App\Encryption::getInstance()->encrypt(\App\Encryption::generatePassword(self::KEY_LENGTH));

Return type of getInstanceById() is undeclared type \self
Open

    public static function getInstanceById($recordId)

Return type of getCleanInstance() is undeclared type \self
Open

    public static function getCleanInstance()

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

        return (new App\Db\Query())->from('w_#__servers')->where($where)->exists();

Call to method generatePassword from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

            $data['api_key'] = App\Encryption::getInstance()->encrypt(\App\Encryption::generatePassword(self::KEY_LENGTH));

Argument 2 (key) is int but \App\Cache::delete() takes string defined at /code/app/Cache.php:105
Open

        \App\Cache::delete('App\Fields\ServerAccess::get', $this->getId());

Declaration of function getName() : \type should be compatible with function getName() : string defined in /code/modules/Settings/Vtiger/models/Record.php:28
Open

    public function getName()

Call to undeclared method \App\Db::createCommand
Open

            $db->createCommand()->insert('w_#__servers', $data)->execute();

Return type of getName() is undeclared type \type
Open

    public function getName()

Call to undeclared method \App\Db::createCommand
Open

        \App\Db::getInstance('webservice')->createCommand()

Call to method getInstance from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

            'pass' => $this->get('pass') ? App\Encryption::getInstance()->encrypt($this->get('pass')) : '',

Call to undeclared method \App\Db::createCommand
Open

            $db->createCommand()->update('w_#__servers', $data, ['id' => $this->getId()])->execute();

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

class Settings_WebserviceApps_Record_Model extends Settings_Vtiger_Record_Model

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

        $db = \App\Db::getInstance('webservice');

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 class Settings_WebserviceApps_Record_Model is not named in CamelCase.
Open

class Settings_WebserviceApps_Record_Model extends Settings_Vtiger_Record_Model
{
    /**
     * Length key.
     */

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

            $model->setData($data);

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

     * Length key.

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

        return $model;

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

        if ($data = \App\Fields\ServerAccess::get($recordId)) {

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

            'status' => $this->get('status') ? 1 : 0,

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

    public function delete()

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

    /**

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

            'name' => $this->get('name'),

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

            $data['api_key'] = App\Encryption::getInstance()->encrypt(\App\Encryption::generatePassword(self::KEY_LENGTH));

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

        if (!$this->isEmpty('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 $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

    public static function getCleanInstance()

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

     *

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

        if (empty($recordId)) {

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

    public function save()

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

        $data = [

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

     * @return 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

    }

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

     * @param int $recordId

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

            return false;

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

        }

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

    private function checkDuplicate(): bool

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

    {

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

        $where = ['and'];

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

     * @return int

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 name server.

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

     * @return \self

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

     * Static function to get model.

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

    public static function getInstanceById($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

        }

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

            ->delete('w_#__servers', ['id' => $this->getId()])

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

     * @return bool

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

    /**

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

            'url' => (string) $this->get('url'),

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

     * Checks if duplicates.

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

        $where[] = ['type' => $this->get('type'), 'name' => $this->get('name')];

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

     * Save record.

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

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

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

     * Function to get instance without data.

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

        $model = self::getCleanInstance();

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

            $where[] = ['<>', 'id', $this->getId()];

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

        $db = \App\Db::getInstance('webservice');

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

        if ($this->checkDuplicate()) {

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

            throw new \App\Exceptions\IllegalValue('ERR_DUPLICATE_LOGIN', 406);

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

        \App\Cache::delete('App\Fields\ServerAccess::get', $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

     */

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

            'ips' => (string) $this->get('ips'),

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

            'pass' => $this->get('pass') ? App\Encryption::getInstance()->encrypt($this->get('pass')) : '',

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

        \App\Db::getInstance('webservice')->createCommand()

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

     */

Line exceeds 120 characters; contains 123 characters
Open

            $data['api_key'] = App\Encryption::getInstance()->encrypt(\App\Encryption::generatePassword(self::KEY_LENGTH));

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

    const KEY_LENGTH = 32;

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

     * Delete the record.

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

        if ($this->isEmpty('id')) {

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

            $db->createCommand()->insert('w_#__servers', $data)->execute();

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

            $this->set('id', $db->getLastInsertID('w_#__servers_id_seq'));

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

        }

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

        \App\Cache::delete('App\Fields\ServerAccess::get', $this->getId());

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

     * Function to 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

        return new self();

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

        return (new App\Db\Query())->from('w_#__servers')->where($where)->exists();

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

            $data['type'] = $this->get('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

     * @return bool|\self

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

            ->execute();

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

            $db->createCommand()->update('w_#__servers', $data, ['id' => $this->getId()])->execute();

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

    }

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

class Settings_WebserviceApps_Record_Model extends Settings_Vtiger_Record_Model

There are no issues that match your filters.

Category
Status