YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
2 hrs
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'), $request->getByType('hash', \App\Purifier::ALNUM));
        if ($request->isAjax()) {
Severity: Minor
Found in modules/Vtiger/files/MultiImage.php by phpmd

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 get has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function get(App\Request $request)
    {
        if ($request->isEmpty('key', 2)) {
            throw new \App\Exceptions\NoPermitted('Not Acceptable', 406);
        }
Severity: Minor
Found in modules/Vtiger/files/MultiImage.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 get has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

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

    Missing class import via use statement (line '44', column '14').
    Open

                throw new \App\Exceptions\NoPermitted('Not Acceptable', 406);
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

    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 '79', column '20').
    Open

                $response = new Vtiger_Response();
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

    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 '68', column '15').
    Open

                    throw new \App\Exceptions\AppException('ERR_FILE_NOT_FOUND', 404);
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

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

            $value = \App\Json::decode($recordModel->get($request->getByType('field', 2)));
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

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

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

    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'],
                    ]);
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

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

            $recordModel = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
    Severity: Critical
    Found in modules/Vtiger/files/MultiImage.php by sonar-php

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

            $value = \App\Json::decode($recordModel->get($request->getByType('field', 2)));
    Severity: Critical
    Found in modules/Vtiger/files/MultiImage.php by sonar-php

    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.

    Argument 2 (emptyFunction) is 2 but \App\Request::isEmpty() takes bool|false defined at /code/app/Request.php:577
    Open

            if ($request->isEmpty('key', 2)) {
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phan

    Call to undeclared method \Vtiger_Base_UIType::uploadTempFile
    Open

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

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

    class Vtiger_MultiImage_File extends Vtiger_MultiAttachment_File

    The class Vtiger_MultiImage_File is not named in CamelCase.
    Open

    class Vtiger_MultiImage_File extends Vtiger_MultiAttachment_File
    {
        /**
         * Storage name.
         *
    Severity: Minor
    Found in modules/Vtiger/files/MultiImage.php by phpmd

    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

         * @throws \App\Exceptions\IllegalValue

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

         * @throws \App\Exceptions\NoPermitted

    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

                        break;

    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

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

    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

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

    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

        }

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

         * Storage name.

    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

         */

    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

         */

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

            $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, $request->isEmpty('record') ? 0 : $request->getInteger('record'), $request->getByType('hash', \App\Purifier::ALNUM));

    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

         * @var string

    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

                $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

        /**

    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

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

    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

            foreach ($value as $item) {

    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

                $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

                }

    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

         * File type.

    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

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

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

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

    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

            $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

         */

    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'],

    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

                        }

    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

        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

                            header('Content-disposition: attachment; filename="' . $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

                    'attach' => $attach,

    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

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

    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

        public function post(App\Request $request)

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

         * @var string

    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

                        readfile($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

        public $storageName = 'MultiImage';

    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

         * View image.

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

         * @throws \App\Exceptions\AppException

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

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

    Line exceeds 120 characters; contains 190 characters
    Open

            $attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, $request->isEmpty('record') ? 0 : $request->getInteger('record'), $request->getByType('hash', \App\Purifier::ALNUM));

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

    class Vtiger_MultiImage_File extends Vtiger_MultiAttachment_File

    There are no issues that match your filters.

    Category
    Status