YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/files/MultiAttachment.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

post accesses the super-global variable $_FILES.
Open

    public function post(App\Request $request)
    {
        $fieldModel = Vtiger_Module_Model::getInstance($request->getModule())->getFieldByName($request->getByType('field', \App\Purifier::ALNUM));
        $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, $request->isEmpty('record') ? 0 : $request->getInteger('record'));
        if ($request->isAjax()) {

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

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

    public function get(App\Request $request)
    {
        if ($request->isEmpty('key', true)) {
            throw new \App\Exceptions\NoPermitted('Not Acceptable', 406);
        }
Severity: Minor
Found in modules/Vtiger/files/MultiAttachment.php - About 1 hr to fix

    Function get has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get(App\Request $request)
        {
            if ($request->isEmpty('key', true)) {
                throw new \App\Exceptions\NoPermitted('Not Acceptable', 406);
            }
    Severity: Minor
    Found in modules/Vtiger/files/MultiAttachment.php - About 45 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 '53', column '15').
    Open

                    throw new \App\Exceptions\AppException('ERR_FILE_NOT_FOUND', 404);

    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 '64', 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 '31', column '14').
    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

    Missing class import via use statement (line '84', column '14').
    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

    Missing class import via use statement (line '97', column '13').
    Open

            throw new \App\Exceptions\AppException('ERR_FILE_NOT_FOUND', 404);

    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 'Vtiger_Record_Model' in method 'get'.
    Open

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

    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\Json' in method 'get'.
    Open

            $value = \App\Json::decode($recordModel->get($request->getByType('field', 2)));

    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\Fields\File' in method 'get'.
    Open

                    $file = \App\Fields\File::loadFromInfo([
                        'path' => ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $item['path'],
                        'name' => $item['name'],
                    ]);

    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\Fields\File' in method 'api'.
    Open

                    return \App\Fields\File::loadFromInfo([
                        'path' => ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $item['path'],
                        'name' => $item['name'],
                    ]);

    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\Json' in method 'api'.
    Open

            $value = \App\Json::decode($recordModel->get($request->getByType('field', \App\Purifier::ALNUM))) ?: [];

    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 'Vtiger_Record_Model' in method 'api'.
    Open

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

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

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

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

            $value = \App\Json::decode($recordModel->get($request->getByType('field', 2)));

    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.

    Call to undeclared method \Vtiger_Base_UIType::uploadTempFile
    Open

            $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, $request->isEmpty('record') ? 0 : $request->getInteger('record'));
    Severity: Critical
    Found in modules/Vtiger/files/MultiAttachment.php by phan

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

    class Vtiger_MultiAttachment_File extends Vtiger_Basic_File

    The class Vtiger_MultiAttachment_File is not named in CamelCase.
    Open

    class Vtiger_MultiAttachment_File extends Vtiger_Basic_File
    {
        /** {@inheritdoc} */
        public $storageName = 'MultiAttachment';
    
    

    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

            $key = $request->getByType('key', 2);

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

            foreach ($value as $item) {

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

                        header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));

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

                        header('Content-length: ' . $file->getSize());

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

         *

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

                        header('Content-transfer-encoding: binary');

    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

        {

    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 ($item['key'] === $key) {

    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

         * @param \App\Request $request

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

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

    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

                        'path' => ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $item['path'],

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

            if ($request->isEmpty('key', true)) {

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

                    if (file_exists($file->getPath())) {

    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

                        'name' => $item['name'],

    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

                    ]);

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

        /**

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

                        header('Content-type: ' . $file->getMimeType());

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

                        break;

    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

        /** {@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

                        header('Pragma: cache');

    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 \App\Fields\File

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

            $value = \App\Json::decode($recordModel->get($request->getByType('field', \App\Purifier::ALNUM))) ?: [];

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

            foreach ($value as $item) {

    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\AppException('ERR_FILE_NOT_FOUND', 404);

    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 = Vtiger_Module_Model::getInstance($request->getModule())->getFieldByName($request->getByType('field', \App\Purifier::ALNUM));

    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

                    return \App\Fields\File::loadFromInfo([

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

            $value = \App\Json::decode($recordModel->get($request->getByType('field', 2)));

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

                    $file = \App\Fields\File::loadFromInfo([

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

                        'name' => $item['name'],

    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 $fileType = '';

    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

                        header('Cache-control: max-age=86400, public');

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

                        header('Content-disposition: attachment; filename="' . $item['name'] . '"');

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

         * Api function to get file.

    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

            if ($request->isEmpty('key', true)) {

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

                if ($item['key'] === $key) {

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

                    throw new \App\Exceptions\AppException('ERR_FILE_NOT_FOUND', 404);

    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

                }

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

         *

    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

         * @param App\Request $request

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

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

    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 = 'MultiAttachment';

    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

                        readfile($file->getPath());

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

        /** {@inheritdoc} */

    Line exceeds 120 characters; contains 146 characters
    Open

            $fieldModel = Vtiger_Module_Model::getInstance($request->getModule())->getFieldByName($request->getByType('field', \App\Purifier::ALNUM));

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

            $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, $request->isEmpty('record') ? 0 : $request->getInteger('record'));

    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

                $response->setResult([

    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

                $response->emit();

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

        public function api(App\Request $request): App\Fields\File

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

        {

    Line exceeds 120 characters; contains 139 characters
    Open

            $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, $request->isEmpty('record') ? 0 : $request->getInteger('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

                        'path' => ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $item['path'],

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

    class Vtiger_MultiAttachment_File extends Vtiger_Basic_File

    There are no issues that match your filters.

    Category
    Status