YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/ModuleManager/actions/Basic.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

Missing class import via use statement (line '62', column '70').
Open

        $paths = array_map('strtolower', array_keys(iterator_to_array((new \RecursiveDirectoryIterator('modules', FilesystemIterator::SKIP_DOTS)))));

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 '39', column '19').
Open

        $response = new Vtiger_Response();

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 '72', column '19').
Open

        $response = new Vtiger_Response();

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

        $response = new Vtiger_Response();

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 '125', column '19').
Open

        $response = new Vtiger_Response();

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 '38', column '29').
Open

        $moduleManagerModel = new Settings_ModuleManager_Module_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 '94', column '30').
Open

            $moduleManagerModel = new Settings_ModuleManager_Module_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 '\App\Language' in method 'checkModuleName'.
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $qualifiedModuleName)];

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

        } else {
            $result = ['success' => false];
        }

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 'Settings_ModuleManager_Module_Model' in method 'createModule'.
Open

        if (!Settings_ModuleManager_Module_Model::checkModuleName($moduleName)) {

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

            } else {
                $moduleManagerModel->disableModule($moduleName);
            }

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\Language' in method 'checkModuleName'.
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_ERROR_MODULE_NAME_CONTAINS_SETTINGS', $qualifiedModuleName)];

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 'vtlib\Module' in method 'deleteModule'.
Open

        $moduleInstance = vtlib\Module::getInstance($moduleName);

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_ModuleManager_Module_Model' in method 'checkModuleName'.
Open

        } elseif (Settings_ModuleManager_Module_Model::checkModuleName($moduleName)) {

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 'vtlib\Module' in method 'checkModuleName'.
Open

        $module = vtlib\Module::getInstance($moduleName);

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

        } else {
            $result = ['success' => true];
        }

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

        } else {
            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $request->getModule(false))];
        }

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\Language' in method 'createModule'.
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $request->getModule(false))];

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\Language' in method 'checkModuleName'.
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_MODULE_ALREADY_EXISTS_TRY_ANOTHER', $qualifiedModuleName)];

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 "Standard" 4 times.
Open

        $moduleName = $request->getByType('forModule', 'Standard');

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.

Define a constant instead of duplicating this literal "success" 9 times.
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_MODULE_ALREADY_EXISTS_TRY_ANOTHER', $qualifiedModuleName)];

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.

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

class Settings_ModuleManager_Basic_Action extends Settings_Vtiger_Basic_Action

The class Settings_ModuleManager_Basic_Action is not named in CamelCase.
Open

class Settings_ModuleManager_Basic_Action extends Settings_Vtiger_Basic_Action
{
    use \App\Controller\ExposeMethod;

    /**

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

     */

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

     * The action enable / disable the module.

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

                $moduleManagerModel->disableModule($moduleName);

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

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_MODULE_ALREADY_EXISTS_TRY_ANOTHER', $qualifiedModuleName)];

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

        $response->emit();

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

            'entityfieldlabel' => 'Text',

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

        $moduleName = $formData['module_name'];

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

            $result = ['success' => true, 'text' => ucfirst($moduleName)];

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

            }

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

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $request->getModule(false))];

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

            $moduleInstance->delete();

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

        $response->setResult($result);

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

        $this->exposeMethod('deleteModule');

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

    }

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

        $moduleName = $request->getByType('forModule', 'Standard');

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

        $formData = $request->getMultiDimensionArray('formData', [

Line exceeds 120 characters; contains 134 characters
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $request->getModule(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

     *

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

    {

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

            'entitytype' => 'Integer'

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

        $response->emit();

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

        $response->emit();

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

    use \App\Controller\ExposeMethod;

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

        $response = new Vtiger_Response();

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

            }

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

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_ERROR_MODULE_NAME_CONTAINS_SETTINGS', $qualifiedModuleName)];

Line exceeds 120 characters; contains 144 characters
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_ERROR_MODULE_NAME_CONTAINS_SETTINGS', $qualifiedModuleName)];

Line exceeds 120 characters; contains 128 characters
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $qualifiedModuleName)];

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 (!Settings_ModuleManager_Module_Model::checkModuleName($moduleName)) {

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

            $moduleManagerModel = new Settings_ModuleManager_Module_Model();

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

            try {

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

     *

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

            } catch (Exception $e) {

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

    /**

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

        $moduleName = $request->getByType('forModule', 'Standard');

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

        $this->exposeMethod('updateModuleStatus');

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

     */

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

        $paths = array_map('strtolower', array_keys(iterator_to_array((new \RecursiveDirectoryIterator('modules', FilesystemIterator::SKIP_DOTS)))));

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

        $response = new Vtiger_Response();

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

            $result = ['success' => false];

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

    public function __construct()

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

        parent::__construct();

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

     *

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

        $response->emit();

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

     *

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

        $module = vtlib\Module::getInstance($moduleName);

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

     * @param \App\Request $request

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

            'entityfieldname' => 'Text',

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

        }

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

        $response->setResult($result);

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

        $moduleInstance = vtlib\Module::getInstance($moduleName);

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

     * @param App\Request $request

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

    {

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

        try {

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

            if ($request->getBoolean('updateStatus')) {

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

    }

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

        $moduleName = ucfirst($request->getByType('moduleName', 'Standard'));

Line exceeds 120 characters; contains 149 characters
Open

        $paths = array_map('strtolower', array_keys(iterator_to_array((new \RecursiveDirectoryIterator('modules', FilesystemIterator::SKIP_DOTS)))));

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

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_INVALID_MODULE_NAME', $qualifiedModuleName)];

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

     * Action to create module.

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

     */

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

            'module_label' => 'Text',

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

     * Action delete module.

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

     * @return void

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 ($module || \in_array('modules' . DIRECTORY_SEPARATOR . strtolower($moduleName), $paths)) {

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

        $response = new Vtiger_Response();

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 checkModuleName(App\Request $request)

Line exceeds 120 characters; contains 142 characters
Open

            $result = ['success' => false, 'text' => \App\Language::translate('LBL_MODULE_ALREADY_EXISTS_TRY_ANOTHER', $qualifiedModuleName)];

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

        } elseif (false !== strpos($moduleName, 'Settings')) {

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 App\Request $request

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

        }

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

        $this->exposeMethod('createModule');

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

     * @return void

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

            $response->setError($e->getCode(), $e->getMessage());

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

     * Action to check module name.

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

        } elseif (Settings_ModuleManager_Module_Model::checkModuleName($moduleName)) {

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

                $result = ['success' => false, 'text' => $e->getMessage()];

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

        $response = new Vtiger_Response();

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

     *

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

        $moduleManagerModel = new Settings_ModuleManager_Module_Model();

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 \App\Request $request

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

        $qualifiedModuleName = $request->getModule(false);

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

        $response->setResult($result);

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 createModule(App\Request $request)

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

    public function deleteModule(App\Request $request)

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

        if ($moduleInstance && 1 === (int) $moduleInstance->customized) {

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

            $result = ['success' => true];

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

     * Construct.

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

    public function updateModuleStatus(App\Request $request)

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

                $moduleManagerModel->enableModule($moduleName);

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

        } catch (\App\Exceptions\NotAllowedMethod $e) {

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

    {

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

            $result = ['success' => true];

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

            'module_name' => 'Standard',

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

    {

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

        $this->exposeMethod('checkModuleName');

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

                $moduleManagerModel->createModule($formData);

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

class Settings_ModuleManager_Basic_Action extends Settings_Vtiger_Basic_Action

There are no issues that match your filters.

Category
Status