YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Media/files/Images.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

post accesses the super-global variable $_FILES.
Open

    public function post(App\Request $request)
    {
        $moduleName = $request->getModule(false);
        $moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
        $fieldModel = $moduleModel->getFieldInstanceByName('image');

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Function post has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function post(App\Request $request)
    {
        $moduleName = $request->getModule(false);
        $moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
        $fieldModel = $moduleModel->getFieldInstanceByName('image');
Severity: Minor
Found in modules/Settings/Media/files/Images.php - About 1 hr 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

Method post has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function post(App\Request $request)
    {
        $moduleName = $request->getModule(false);
        $moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
        $fieldModel = $moduleModel->getFieldInstanceByName('image');
Severity: Minor
Found in modules/Settings/Media/files/Images.php - About 1 hr to fix

    Missing class import via use statement (line '67', column '20').
    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 '13').
    Open

            throw new \App\Exceptions\NoPermitted('Not Acceptable', 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

    The method post uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    Settings_Vtiger_Tracker_Model::addBasic('save');
                    $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, 0);
                    $result = [
                        'field' => $fieldModel->getName(),

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

        public function post(App\Request $request)
        {
            $moduleName = $request->getModule(false);
            $moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
            $fieldModel = $moduleModel->getFieldInstanceByName('image');

    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 'Settings_Vtiger_Tracker_Model' in method 'post'.
    Open

                    Settings_Vtiger_Tracker_Model::addBasic('delete');

    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_Module_Model' in method 'post'.
    Open

            $moduleModel = Settings_Vtiger_Module_Model::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_Vtiger_Tracker_Model' in method 'post'.
    Open

                        Settings_Vtiger_Tracker_Model::addDetail(['key' => $key], ['key' => '']);

    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 'post'.
    Open

                    Settings_Vtiger_Tracker_Model::addBasic('save');

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

        public function post(App\Request $request)
        {
            $moduleName = $request->getModule(false);
            $moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
            $fieldModel = $moduleModel->getFieldInstanceByName('image');

    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 'Settings_Vtiger_Tracker_Model' in method 'post'.
    Open

                        Settings_Vtiger_Tracker_Model::addDetail(['key' => ''], ['key' => implode(',', $keys)]);

    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 parameters such as '$request'.
    Open

        public function get(App\Request $request)

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

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

    Call to undeclared method \Settings_Vtiger_Module_Model::getFieldInstanceByName
    Open

            $fieldModel = $moduleModel->getFieldInstanceByName('image');
    Severity: Critical
    Found in modules/Settings/Media/files/Images.php by phan

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

    class Settings_Media_Images_File extends Vtiger_Basic_File

    The class Settings_Media_Images_File is not named in CamelCase.
    Open

    class Settings_Media_Images_File extends Vtiger_Basic_File
    {
        use \App\Controller\Traits\SettingsPermission;
    
        /** {@inheritdoc} */

    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

        /** {@inheritdoc} */

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

        /** {@inheritdoc} */

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

        use \App\Controller\Traits\SettingsPermission;

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

                    Settings_Vtiger_Tracker_Model::addBasic('delete');

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

        public $fileType = 'image';

    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 postCheckPermission(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

                $response->emit();

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

                        'module' => $fieldModel->getModuleName(),

    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

            throw new \App\Exceptions\NoPermitted('Not Acceptable', 406);

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

            if ($request->isAjax()) {

    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

                    $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, 0);

    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

                    if ($result = $fieldModel->getUITypeModel()->removeImage($key)) {

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

                        Settings_Vtiger_Tracker_Model::addDetail(['key' => $key], ['key' => '']);

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

        public function get(App\Request $request)

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

            $this->checkPermission($request);

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

            $moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);

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

                    $result = [

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

        /** {@inheritdoc} */

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

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

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

                    if ($attach && $keys = array_column($attach, 'key')) {

    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

         * Get attachment.

    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

            $moduleName = $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

        public function post(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

                    $key = $request->getByType('key', \App\Purifier::ALNUM);

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

        public $storageName = 'public_html/Media/Images';

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

            return true;

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

                    Settings_Vtiger_Tracker_Model::addBasic('save');

    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 = $moduleModel->getFieldInstanceByName('image');

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

                        'field' => $fieldModel->getName(),

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

                        'attach' => $attach,

    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(['key' => ''], ['key' => implode(',', $keys)]);

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

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

    class Settings_Media_Images_File extends Vtiger_Basic_File

    There are no issues that match your filters.

    Category
    Status