YetiForceCompany/YetiForceCRM

View on GitHub
app/Controller/Traits/RecordSettings.php

Summary

Maintainability
A
45 mins
Test Coverage
F
0%

Avoid using static access to class '\Vtiger_Link_Model' in method 'getRecordLinks'.
Open

            $links[] = \Vtiger_Link_Model::getInstanceFromValues($recordLink);

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 \App\Controller\Traits\RecordSettings::set
Open

                $this->set($fieldName, $fieldModel->getDBValue($value));
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

Call to undeclared method \App\Controller\Traits\RecordSettings::get
Open

        return $this->get('url');
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

Call to undeclared method \App\Controller\Traits\RecordSettings::getEditViewUrl
Open

                'linkdata' => ['url' => $this->getEditViewUrl()],
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

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

        return \App\Db::getInstance()->createCommand()
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

Call to undeclared method \App\Controller\Traits\RecordSettings::get
Open

        return $this->get('id');
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

Return type of getRecordLinks() is undeclared type \App\Controller\Traits\Vtiger_Link_Model[]
Open

    public function getRecordLinks(): array

Call to undeclared method \App\Controller\Traits\RecordSettings::getFieldInstanceByName
Open

                $fieldModel = $this->getFieldInstanceByName($fieldName)->getUITypeModel();
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

Call to undeclared method \App\Controller\Traits\RecordSettings::getModule
Open

            ->delete($this->getModule()->baseTable, ['id' => $this->getId()])
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

Call to undeclared method \App\Controller\Traits\RecordSettings::getModule
Open

        foreach ($this->getModule()->getFormFields() as $fieldName => $fieldInfo) {
Severity: Critical
Found in app/Controller/Traits/RecordSettings.php by phan

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

    public function setDataFromRequest(\App\Request $request): void
    {
        foreach ($this->getModule()->getFormFields() as $fieldName => $fieldInfo) {
            if ($request->has($fieldName)) {
                $value = $request->getByType($fieldName, $fieldInfo['purifyType']);
Severity: Minor
Found in app/Controller/Traits/RecordSettings.php and 1 other location - About 45 mins to fix
modules/Settings/MeetingServices/models/Record.php on lines 149..159

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

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

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

     * Record ID.

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

        $links = [];

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

                $value = $request->getByType($fieldName, $fieldInfo['purifyType']);

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

                $this->set($fieldName, $fieldModel->getDBValue($value));

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

        foreach ([

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

     *

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

                'linklabel' => 'BTN_RECORD_EDIT',

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

            [

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

                'linkicon' => 'fas fa-trash-alt',

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

     * Function to delete the current record model.

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

     *

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 = $this->getFieldInstanceByName($fieldName)->getUITypeModel();

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

     * @return int

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

            $links[] = \Vtiger_Link_Model::getInstanceFromValues($recordLink);

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('url');

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

     * Get record links.

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

                'linkclass' => 'btn btn-sm btn-primary js-edit-record-modal',

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

     *

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

    {

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

                'linkdata' => ['url' => $this->getEditViewUrl()],

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

                'linktype' => 'LISTVIEWRECORD',

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

                'linklabel' => 'LBL_DELETE_RECORD',

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

            if ($request->has($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

    public function getName()

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

     * Sets data from request.

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

        foreach ($this->getModule()->getFormFields() as $fieldName => $fieldInfo) {

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

                $fieldModel->validate($value, 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

                'linkicon' => 'yfi yfi-full-editing-view',

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

                'linktype' => 'LISTVIEWRECORD',

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 int

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

            ->delete($this->getModule()->baseTable, ['id' => $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

     * Record name.

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

    public function getRecordLinks(): array

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

    public function delete(): int

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

                'linkurl' => "javascript:Settings_Vtiger_List_Js.deleteById('{$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

        ] as $recordLink) {

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 $links;

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

     * @return Vtiger_Link_Model[]

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

                'linkclass' => 'btn btn-sm btn-danger text-white',

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 \App\Db::getInstance()->createCommand()

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

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

There are no issues that match your filters.

Category
Status