YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Companies/actions/SaveAjax.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Function process has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function process(App\Request $request): void
    {
        try {
            $recordModel = Settings_Companies_Record_Model::getInstance();
            $fields = $recordModel->getModule()->getFormFields();
Severity: Minor
Found in modules/Settings/Companies/actions/SaveAjax.php - About 55 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 '49', 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 '32', column '17').
Open

                        throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');

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 'Settings_Companies_Record_Model' in method 'process'.
Open

            $recordModel = Settings_Companies_Record_Model::getInstance();

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_Vtiger_Tracker_Model' in method 'process'.
Open

            \Settings_Vtiger_Tracker_Model::addDetail($recordModel->getPreviousValue(), $recordId ? array_intersect_key($recordModel->getData(), $recordModel->getPreviousValue()) : $recordModel->getData());

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 unused local variables such as '$mas'.
Open

                    if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

Call to method getFormFields from undeclared class \Settings_Companies_Module_Model
Open

            $fields = $recordModel->getModule()->getFormFields();

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

                if ($request->has($fieldName) && !$fieldModel->isEditableReadOnly()) {
                    $value = $request->getRaw($fieldName);
                    if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {
                        throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');
                    }
Severity: Major
Found in modules/Settings/Companies/actions/SaveAjax.php and 1 other location - About 1 hr to fix
modules/Settings/YetiForce/actions/Buy.php on lines 34..44

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 106.

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_Companies_SaveAjax_Action extends Settings_Vtiger_Basic_Action

The class Settings_Companies_SaveAjax_Action is not named in CamelCase.
Open

class Settings_Companies_SaveAjax_Action extends Settings_Vtiger_Basic_Action
{
    /**
     * Function to save and register company info.
     *

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

            $recordModel->save();

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

                    $fieldModel->getUITypeModel()->validate($value, true);

Line exceeds 120 characters; contains 206 characters
Open

            \Settings_Vtiger_Tracker_Model::addDetail($recordModel->getPreviousValue(), $recordId ? array_intersect_key($recordModel->getData(), $recordModel->getPreviousValue()) : $recordModel->getData());

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 (array_keys($fields) as $fieldName) {

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

    }

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

     * @throws \App\Exceptions\DbException

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

            $recordModel = Settings_Companies_Record_Model::getInstance();

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

            $fields = $recordModel->getModule()->getFormFields();

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

            $result = ['success' => false, 'message' => $e->getDisplayMessage()];

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

                if ($request->has($fieldName) && !$fieldModel->isEditableReadOnly()) {

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

                    if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {

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, 'url' => $recordModel->getEditViewUrl()];

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

    public function process(App\Request $request): void

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

     * @throws \App\Exceptions\IllegalValue

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

                    $value = $request->getRaw($fieldName);

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

                    }

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

                    $value = $request->getByType($fieldName, $fieldModel->get('purifyType'));

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 = new Vtiger_Response();

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

     * @throws \App\Exceptions\Security

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

                $fieldModel = $recordModel->getFieldInstanceByName($fieldName);

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

     * Function to save and register company info.

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->set($fieldName, $fieldModel->getDBValue($value));

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

        } catch (\App\Exceptions\AppException $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

        $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

            \Settings_Vtiger_Tracker_Model::addDetail($recordModel->getPreviousValue(), $recordId ? array_intersect_key($recordModel->getData(), $recordModel->getPreviousValue()) : $recordModel->getData());

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

        try {

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

                        throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');

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

            $recordId = $recordModel->getId();

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

class Settings_Companies_SaveAjax_Action extends Settings_Vtiger_Basic_Action

There are no issues that match your filters.

Category
Status