YetiForceCompany/YetiForceCRM

View on GitHub
modules/Documents/models/Record.php

Summary

Maintainability
D
2 days
Test Coverage
F
51%

isMandatorySave accesses the super-global variable $_FILES.
Open

    public function isMandatorySave()
    {
        return parent::isMandatorySave() || $_FILES;
    }
Severity: Minor
Found in modules/Documents/models/Record.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

saveToDb accesses the super-global variable $_FILES.
Open

    public function saveToDb()
    {
        $db = \App\Db::getInstance();
        $fileNameByField = 'filename';
        if ('I' === $this->get('filelocationtype')) {
Severity: Minor
Found in modules/Documents/models/Record.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

The class Documents_Record_Model has an overall complexity of 68 which is very high. The configured complexity threshold is 50.
Open

class Documents_Record_Model extends Vtiger_Record_Model
{
    /** @var string[] Types included in the preview of the file. */
    public $filePreview = [
        'application/pdf', 'image/png', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff'
Severity: Minor
Found in modules/Documents/models/Record.php by phpmd

Function saveToDb has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    public function saveToDb()
    {
        $db = \App\Db::getInstance();
        $fileNameByField = 'filename';
        if ('I' === $this->get('filelocationtype')) {
Severity: Minor
Found in modules/Documents/models/Record.php - About 3 hrs 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

File Record.php has 281 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

 /* +***********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
Severity: Minor
Found in modules/Documents/models/Record.php - About 2 hrs to fix

    Function downloadFiles has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function downloadFiles($recordsIds)
        {
            $zip = new ZipArchive();
            $postfix = time() . '_' . random_int(0, 1000);
            $zipPath = ROOT_DIRECTORY . '/cache/';
    Severity: Minor
    Found in modules/Documents/models/Record.php - About 2 hrs 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 saveToDb has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function saveToDb()
        {
            $db = \App\Db::getInstance();
            $fileNameByField = 'filename';
            if ('I' === $this->get('filelocationtype')) {
    Severity: Minor
    Found in modules/Documents/models/Record.php - About 1 hr to fix

      Method downloadFiles has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function downloadFiles($recordsIds)
          {
              $zip = new ZipArchive();
              $postfix = time() . '_' . random_int(0, 1000);
              $zipPath = ROOT_DIRECTORY . '/cache/';
      Severity: Minor
      Found in modules/Documents/models/Record.php - About 1 hr to fix

        Method uploadAndSaveFile has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function uploadAndSaveFile($fileDetails)
            {
                $id = $this->getId();
                $moduleName = $this->getModuleName();
                $result = false;
        Severity: Minor
        Found in modules/Documents/models/Record.php - About 1 hr to fix

          Function getFilePath has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getFilePath(): string
              {
                  $path = '';
                  if ($fileDetails = $this->getFileDetails()) {
                      $fileName = $fileDetails['name'];
          Severity: Minor
          Found in modules/Documents/models/Record.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 downloadFile has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function downloadFile()
              {
                  $fileContent = false;
                  if ($path = $this->getFilePath()) {
                      $fileDetails = $this->getFileDetails();
          Severity: Minor
          Found in modules/Documents/models/Record.php - About 1 hr to fix

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

                public function downloadFile()
                {
                    $fileContent = false;
                    if ($path = $this->getFilePath()) {
                        $fileDetails = $this->getFileDetails();
            Severity: Minor
            Found in modules/Documents/models/Record.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

            Function delete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public function delete()
                {
                    parent::delete();
                    $dbCommand = \App\Db::getInstance()->createCommand();
                    $attachmentsIds = (new \App\Db\Query())->select(['attachmentsid'])->from('vtiger_seattachmentsrel')->where(['crmid' => $this->getId()])->column();
            Severity: Minor
            Found in modules/Documents/models/Record.php - About 25 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

            The method saveToDb() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
            Open

                public function saveToDb()
                {
                    $db = \App\Db::getInstance();
                    $fileNameByField = 'filename';
                    if ('I' === $this->get('filelocationtype')) {
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
            Open

                public static function downloadFiles($recordsIds)
            Severity: Critical
            Found in modules/Documents/models/Record.php by sonar-php

            Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

            See

            Refactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed.
            Open

                public function saveToDb()
            Severity: Critical
            Found in modules/Documents/models/Record.php by sonar-php

            Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

            See

            Missing class import via use statement (line '104', column '30').
            Open

                        $this->fileDetails = (new \App\Db\Query())->from('vtiger_attachments')
            Severity: Minor
            Found in modules/Documents/models/Record.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 '178', column '14').
            Open

                    $zip = new ZipArchive();
            Severity: Minor
            Found in modules/Documents/models/Record.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 '382', column '26').
            Open

                    $attachmentsIds = (new \App\Db\Query())->select(['attachmentsid'])->from('vtiger_seattachmentsrel')->where(['crmid' => $this->getId()])->column();
            Severity: Minor
            Found in modules/Documents/models/Record.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 '230', column '25').
            Open

                    $downloadCount = (new \App\Db\Query())->select(['filedownloadcount'])->from('vtiger_notes')->where(['notesid' => $notesId])->scalar();
            Severity: Minor
            Found in modules/Documents/models/Record.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 '253', column '15').
            Open

                    return (new App\Db\Query())->select(['vtiger_crmentity.setype'])->from('vtiger_crmentity')->innerJoin('vtiger_senotesrel', 'vtiger_senotesrel.crmid = vtiger_crmentity.crmid')->where(['vtiger_crmentity.deleted' => 0, 'vtiger_senotesrel.notesid' => $record])->distinct()->column();
            Severity: Minor
            Found in modules/Documents/models/Record.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 '384', column '23').
            Open

                        $dataReader = (new \App\Db\Query())->select(['path', 'attachmentsid'])->from('vtiger_attachments')->where(['attachmentsid' => $attachmentsIds])->createCommand()->query();
            Severity: Minor
            Found in modules/Documents/models/Record.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 '184', column '14').
            Open

                        throw new \App\Exceptions\NoPermitted("cannot open <$fileName>");
            Severity: Minor
            Found in modules/Documents/models/Record.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\Fields\File' in method 'downloadFile'.
            Open

                            return \App\Fields\File::loadFromInfo([
                                'path' => $filePath,
                                'name' => $fileDetails['name'],
                                'mimeType' => $fileDetails['type'],
                            ]);
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                            } else {
                                header("content-disposition: attachment; filename=\"$fileName\"");
                            }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class '\App\Layout\Icon' in method 'getFileIconByFileType'.
            Open

                    return \App\Layout\Icon::getIconByFileType($fileType);
            Severity: Minor
            Found in modules/Documents/models/Record.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 'saveToDb'.
            Open

                            if (UPLOAD_ERR_OK === $file['error'] && ($fileInstance = \App\Fields\File::loadFromRequest($file)) && $fileInstance->validateAndSecure()) {
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                    } else {
                        $db->createCommand()->delete('vtiger_seattachmentsrel', ['crmid' => $this->getId()])->execute();
                    }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class '\App\Log' in method 'uploadAndSaveFile'.
            Open

                    \App\Log::trace('Exiting uploadAndSaveFile');
            Severity: Minor
            Found in modules/Documents/models/Record.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\Config' in method 'checkFileIntegrity'.
            Open

                        $fileName = html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));
            Severity: Minor
            Found in modules/Documents/models/Record.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 assigning values to variables in if clauses and the like (line '189', column '8').
            Open

                public static function downloadFiles($recordsIds)
                {
                    $zip = new ZipArchive();
                    $postfix = time() . '_' . random_int(0, 1000);
                    $zipPath = ROOT_DIRECTORY . '/cache/';
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 '\App\Log' in method 'uploadAndSaveFile'.
            Open

                    \App\Log::trace("Entering into uploadAndSaveFile($id,$moduleName) method.");
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                            } else {
                                $savedFile = $fileDetails['attachmentsid'] . '_' . $fileName;
                            }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class 'Vtiger_Link_Model' in method 'getRecordListViewLinksLeftSide'.
            Open

                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([
                            'linklabel' => 'LBL_PREVIEW_FILE',
                            'linkhref' => true,
                            'linkurl' => $this->getDownloadFileURL() . '&show=1',
                            'linkicon' => 'fas fa-binoculars',
            Severity: Minor
            Found in modules/Documents/models/Record.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\Config' in method 'getFilePath'.
            Open

                            $fileName = html_entity_decode($fileName, ENT_QUOTES, \App\Config::main('default_charset'));
            Severity: Minor
            Found in modules/Documents/models/Record.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 assigning values to variables in if clauses and the like (line '154', column '7').
            Open

                public function getFilePath(): string
                {
                    $path = '';
                    if ($fileDetails = $this->getFileDetails()) {
                        $fileName = $fileDetails['name'];
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

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

                    $fileInstance = \App\Fields\File::loadFromRequest($fileDetails);
            Severity: Minor
            Found in modules/Documents/models/Record.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\Db' in method 'uploadAndSaveFile'.
            Open

                    $db = \App\Db::getInstance();
            Severity: Minor
            Found in modules/Documents/models/Record.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 'uploadAndSaveFile'.
            Open

                    $uploadFilePath = \App\Fields\File::initStorageFileDirectory($moduleName);
            Severity: Minor
            Found in modules/Documents/models/Record.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\Config' in method 'uploadAndSaveFile'.
            Open

                    if (\App\Config::module($this->getModuleName(), 'storagePath')) {
            Severity: Minor
            Found in modules/Documents/models/Record.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 'saveToDb'.
            Open

                                \App\Log::error("Error while saving a file, saving failed. | ID: {$this->getId()} | File: {$file['name']} | Error: " . \App\Fields\File::getErrorMessage($file['error']));
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                    } else {
                        $db->createCommand()->delete('vtiger_attachments', ['attachmentsid' => $currentId])->execute();
                    }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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

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

                                } else {
                                    $savedFile = $fileDetails['attachmentsid'] . '_' . html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));
                                }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class 'App\Purifier' in method 'saveToDb'.
            Open

                                $this->setFieldValue('filename', \App\Purifier::decodeHtml(App\Purifier::purify($file['name'])))
            Severity: Minor
            Found in modules/Documents/models/Record.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_Link_Model' in method 'getRecordRelatedListViewLinksLeftSide'.
            Open

                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([
                            'linklabel' => 'LBL_PREVIEW_FILE',
                            'linkhref' => true,
                            'linkurl' => $this->getDownloadFileURL() . '&show=1',
                            'linkicon' => 'fas fa-binoculars',
            Severity: Minor
            Found in modules/Documents/models/Record.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 assigning values to variables in if clauses and the like (line '299', column '46').
            Open

                public function saveToDb()
                {
                    $db = \App\Db::getInstance();
                    $fileNameByField = 'filename';
                    if ('I' === $this->get('filelocationtype')) {
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

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

                public function checkFileIntegrity()
                {
                    $returnValue = false;
                    if ('I' === $this->get('filelocationtype') && ($fileDetails = $this->getFileDetails())) {
                        $fileName = html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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

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

                        } else {
                            $file = $_FILES[$fileNameByField] ?? [];
                        }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class '\App\Config' in method 'downloadFiles'.
            Open

                                    $savedFile = $fileDetails['attachmentsid'] . '_' . html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                    } else {
                        $destinyFilePath = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $uploadFilePath . $currentId;
                    }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class '\App\Request' in method 'saveToDb'.
            Open

                            $file['original_name'] = \App\Request::_get('0_hidden');
            Severity: Minor
            Found in modules/Documents/models/Record.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 'downloadFiles'.
            Open

                    header('content-type: ' . \App\Fields\File::getMimeContentType($fileName));
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                            } else {
                                \App\Log::error("Error while saving a file, saving failed. | ID: {$this->getId()} | File: {$file['name']} | Error: " . \App\Fields\File::getErrorMessage($file['error']));
                                $file = [];
                            }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 using static access to class '\App\Log' in method 'saveToDb'.
            Open

                                \App\Log::error("Error while saving a file, saving failed. | ID: {$this->getId()} | File: {$file['name']} | Error: " . \App\Fields\File::getErrorMessage($file['error']));
            Severity: Minor
            Found in modules/Documents/models/Record.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 assigning values to variables in if clauses and the like (line '118', column '7').
            Open

                public function downloadFile()
                {
                    $fileContent = false;
                    if ($path = $this->getFilePath()) {
                        $fileDetails = $this->getFileDetails();
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

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

                public function getDownloadFileURL()
                {
                    if ('I' === $this->getValueByField('filelocationtype') && ($fileDetails = $this->getFileDetails())) {
                        return 'file.php?module=' . $this->getModuleName() . '&action=DownloadFile&record=' . $this->getId() . '&fileid=' . $fileDetails['attachmentsid'];
                    }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 '\App\Log' in method 'downloadFiles'.
            Open

                        \App\Log::error("cannot open <$fileName>\n");
            Severity: Minor
            Found in modules/Documents/models/Record.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\Purifier' in method 'uploadAndSaveFile'.
            Open

                        'name' => ltrim(App\Purifier::purify($fileName)),
            Severity: Minor
            Found in modules/Documents/models/Record.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\Purifier' in method 'saveToDb'.
            Open

                                $this->setFieldValue('filename', \App\Purifier::decodeHtml(App\Purifier::purify($file['name'])))
            Severity: Minor
            Found in modules/Documents/models/Record.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\Db' in method 'saveToDb'.
            Open

                    $db = \App\Db::getInstance();
            Severity: Minor
            Found in modules/Documents/models/Record.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

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

                        } else {
                            $file = [];
                        }
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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

            Define a constant instead of duplicating this literal "notesid" 3 times.
            Open

                    App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filestatus' => $status], ['notesid' => $this->get('id')])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.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 "error" 3 times.
            Open

                        if (!empty($file['name']) && isset($file['error']) && $file['size'] > 0) {
            Severity: Critical
            Found in modules/Documents/models/Record.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 "LBL_PREVIEW_FILE" 4 times.
            Open

                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([
            Severity: Critical
            Found in modules/Documents/models/Record.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 "filelocationtype" 7 times.
            Open

                    if ('I' === $this->getValueByField('filelocationtype') && ($fileDetails = $this->getFileDetails())) {
            Severity: Critical
            Found in modules/Documents/models/Record.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 "vtiger_seattachmentsrel" 5 times.
            Open

                            ->innerJoin('vtiger_seattachmentsrel', 'vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid')
            Severity: Critical
            Found in modules/Documents/models/Record.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 "filetype" 4 times.
            Open

                    if (!$this->isReadOnly() && \in_array($this->getValueByField('filetype'), $this->filePreview)) {
            Severity: Critical
            Found in modules/Documents/models/Record.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 "crmid" 5 times.
            Open

                            ->where(['crmid' => $this->get('id')])
            Severity: Critical
            Found in modules/Documents/models/Record.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 "filedownloadcount" 4 times.
            Open

                    $downloadCount = (new \App\Db\Query())->select(['filedownloadcount'])->from('vtiger_notes')->where(['notesid' => $notesId])->scalar();
            Severity: Critical
            Found in modules/Documents/models/Record.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 "image/jpeg" 3 times.
            Open

                    'application/pdf', 'image/png', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff'
            Severity: Critical
            Found in modules/Documents/models/Record.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 "default_charset" 3 times.
            Open

                        $fileName = html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));
            Severity: Critical
            Found in modules/Documents/models/Record.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 "filename" 6 times.
            Open

                    return $this->get('filename');
            Severity: Critical
            Found in modules/Documents/models/Record.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 "attachmentsid" 15 times.
            Open

                        return 'file.php?module=' . $this->getModuleName() . '&action=DownloadFile&record=' . $this->getId() . '&fileid=' . $fileDetails['attachmentsid'];
            Severity: Critical
            Found in modules/Documents/models/Record.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 "original_name" 3 times.
            Open

                            $file['original_name'] = \App\Request::_get('0_hidden');
            Severity: Critical
            Found in modules/Documents/models/Record.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 "vtiger_notes" 3 times.
            Open

                    App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filestatus' => $status], ['notesid' => $this->get('id')])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.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 "vtiger_attachments" 5 times.
            Open

                        $this->fileDetails = (new \App\Db\Query())->from('vtiger_attachments')
            Severity: Critical
            Found in modules/Documents/models/Record.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.

            Avoid unused local variables such as '$match'.
            Open

                        if (!empty($fileName) && !preg_match('/^\w{1,5}:\/\/|^\w{0,3}:?\\\\\\\\/', trim($fileName), $match)) {
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            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 undeclared method \App\Db\Query::select
            Open

                    $downloadCount = (new \App\Db\Query())->select(['filedownloadcount'])->from('vtiger_notes')->where(['notesid' => $notesId])->scalar();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->file (Did you mean $file)
            Open

                                $this->file = [];
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->file
            Open

                        if (isset($this->file)) {
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

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

                    App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filestatus' => $status], ['notesid' => $this->get('id')])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to method error from undeclared class \App\Log
            Open

                                \App\Log::error("Error while saving a file, saving failed. | ID: {$this->getId()} | File: {$file['name']} | Error: " . \App\Fields\File::getErrorMessage($file['error']));
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->file (Did you mean $file)
            Open

                            if ($this->uploadAndSaveFile($file) && isset($this->file)) {
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->fileDetails
            Open

                    return $this->fileDetails;
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

            Call to method error from undeclared class \App\Log
            Open

                        \App\Log::error("cannot open <$fileName>\n");
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

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

                        $db->createCommand()->delete('vtiger_seattachmentsrel', ['crmid' => $id])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to undeclared method \App\Db\Query::select
            Open

                        $dataReader = (new \App\Db\Query())->select(['path', 'attachmentsid'])->from('vtiger_attachments')->where(['attachmentsid' => $attachmentsIds])->createCommand()->query();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->file
            Open

                            $file = $this->file;
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

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

                        $db->createCommand()->delete('vtiger_attachments', ['attachmentsid' => $currentId])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to undeclared method \App\Db\Query::select
            Open

                    $attachmentsIds = (new \App\Db\Query())->select(['attachmentsid'])->from('vtiger_seattachmentsrel')->where(['crmid' => $this->getId()])->column();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to undeclared method \App\Db\Query::from
            Open

                        $this->fileDetails = (new \App\Db\Query())->from('vtiger_attachments')
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->fileDetails
            Open

                        $this->fileDetails = (new \App\Db\Query())->from('vtiger_attachments')
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

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

                    \App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filedownloadcount' => ++$downloadCount], ['notesid' => $notesId])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to undeclared method \App\Db\Query::select
            Open

                    return (new App\Db\Query())->select(['vtiger_crmentity.setype'])->from('vtiger_crmentity')->innerJoin('vtiger_senotesrel', 'vtiger_senotesrel.crmid = vtiger_crmentity.crmid')->where(['vtiger_crmentity.deleted' => 0, 'vtiger_senotesrel.notesid' => $record])->distinct()->column();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

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

                        $db->createCommand()->insert('vtiger_seattachmentsrel', ['crmid' => $id, 'attachmentsid' => $currentId])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to method trace from undeclared class \App\Log
            Open

                    \App\Log::trace('Exiting uploadAndSaveFile');
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

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

                    $dbCommand = \App\Db::getInstance()->createCommand();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Reference to undeclared property \Documents_Record_Model->fileDetails
            Open

                    if (!isset($this->fileDetails)) {
            Severity: Minor
            Found in modules/Documents/models/Record.php by phan

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

                        $db->createCommand()->delete('vtiger_seattachmentsrel', ['crmid' => $this->getId()])->execute();
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

            Call to method trace from undeclared class \App\Log
            Open

                    \App\Log::trace("Entering into uploadAndSaveFile($id,$moduleName) method.");
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

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

                    $db->createCommand()->insert('vtiger_attachments', [
            Severity: Critical
            Found in modules/Documents/models/Record.php by phan

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

                    if (!$this->isReadOnly() && \in_array($this->getValueByField('filetype'), $this->filePreview)) {
                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([
                            'linklabel' => 'LBL_PREVIEW_FILE',
                            'linkhref' => true,
                            'linkurl' => $this->getDownloadFileURL() . '&show=1',
            Severity: Minor
            Found in modules/Documents/models/Record.php and 1 other location - About 30 mins to fix
            modules/Documents/models/Record.php on lines 57..66

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

            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

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

                    if (!$this->isReadOnly() && \in_array($this->getValueByField('filetype'), $this->filePreview)) {
                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([
                            'linklabel' => 'LBL_PREVIEW_FILE',
                            'linkhref' => true,
                            'linkurl' => $this->getDownloadFileURL() . '&show=1',
            Severity: Minor
            Found in modules/Documents/models/Record.php and 1 other location - About 30 mins to fix
            modules/Documents/models/Record.php on lines 40..49

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

            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 Documents_Record_Model extends Vtiger_Record_Model

            The class Documents_Record_Model is not named in CamelCase.
            Open

            class Documents_Record_Model extends Vtiger_Record_Model
            {
                /** @var string[] Types included in the preview of the file. */
                public $filePreview = [
                    'application/pdf', 'image/png', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff'
            Severity: Minor
            Found in modules/Documents/models/Record.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

            Avoid variables with short names like $db. Configured minimum length is 3.
            Open

                    $db = \App\Db::getInstance();
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            Avoid variables with short names like $id. Configured minimum length is 3.
            Open

                    $id = $this->getId();
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            Avoid variables with short names like $db. Configured minimum length is 3.
            Open

                    $db = \App\Db::getInstance();
            Severity: Minor
            Found in modules/Documents/models/Record.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            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

                {

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

                 * Get download file url.

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

                /** @var string[] Types included in the preview of the file. */

            Line exceeds 120 characters; contains 158 characters
            Open

                        return 'file.php?module=' . $this->getModuleName() . '&action=DownloadFile&record=' . $this->getId() . '&fileid=' . $fileDetails['attachmentsid'];

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

            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

                        return 'file.php?module=' . $this->getModuleName() . '&action=DownloadFile&record=' . $this->getId() . '&fileid=' . $fileDetails['attachmentsid'];

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

                public function getDownloadFileURL()

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

                    return $this->get('filename');

            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

                    'application/pdf', 'image/png', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff'

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

                    if ('I' === $this->getValueByField('filelocationtype') && ($fileDetails = $this->getFileDetails())) {

            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

                            'linkurl' => $this->getDownloadFileURL() . '&show=1',

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

                 */

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

                 * Check file integrity.

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

                        $fileName = html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));

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

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

                            ->one();

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

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

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

                        if (fopen($filePath, 'r')) {

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

                                header('content-disposition: inline');

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

                            $filePath = $fileDetails['path'];

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

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

                    return array_merge($links, parent::getRecordListViewLinksLeftSide());

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

                            'linkhref' => true,

            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

                    $returnValue = false;

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

                 * Download 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

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

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

                {

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

                        \App\Log::error("cannot open <$fileName>\n");

            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

                    $links = [];

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

                    if (!$this->isReadOnly() && \in_array($this->getValueByField('filetype'), $this->filePreview)) {

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

                 * @return bool

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

                public function checkFileIntegrity()

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

                        $returnValue = (file_exists($savedFile) && fopen($savedFile, 'r')) || (file_exists("{$savedFile}_{$fileName}") && fopen("{$savedFile}_{$fileName}", 'r'));

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

                    if (!isset($this->fileDetails)) {

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

                }

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

                    $fileContent = 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 getFilePath(): string

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

                            $fileName = html_entity_decode($fileName, ENT_QUOTES, \App\Config::main('default_charset'));

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

                                $savedFile = $fileDetails['attachmentsid'];

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

                        }

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

                    $zip = new ZipArchive();

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

                    foreach ($recordsIds as $recordId) {

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

                            if ('I' === $documentModel->get('filelocationtype')) {

            Line exceeds 120 characters; contains 162 characters
            Open

                    'application/pdf', 'image/png', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/bmp', 'image/vnd.microsoft.icon', 'image/tiff', 'image/tiff'

            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 (!$this->isReadOnly() && \in_array($this->getValueByField('filetype'), $this->filePreview)) {

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

                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([

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

                            'linkurl' => $this->getDownloadFileURL() . '&show=1',

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

                            'linkclass' => 'btn-sm btn-light',

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

                public function getRecordRelatedListViewLinksLeftSide(Vtiger_RelationListView_Model $viewModel)

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

                            'linklabel' => 'LBL_PREVIEW_FILE',

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

                public function checkFileIntegrityURL()

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

                    if ($path = $this->getFilePath()) {

            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 127 characters
            Open

                            if (file_exists(ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $fileDetails['path'] . $fileDetails['attachmentsid'])) {

            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

                public $filePreview = [

            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

                 *

            Line exceeds 120 characters; contains 166 characters
            Open

                        $returnValue = (file_exists($savedFile) && fopen($savedFile, 'r')) || (file_exists("{$savedFile}_{$fileName}") && fopen("{$savedFile}_{$fileName}", 'r'));

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

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

                            $fileContent = fread(fopen($filePath, 'r'), $fileSize);

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

                            if ($this->get('show')) {

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

                                header("content-disposition: attachment; filename=\"$fileName\"");

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

                 * Download files.

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

                    $zipPath = ROOT_DIRECTORY . '/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

                            ->innerJoin('vtiger_seattachmentsrel', 'vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid')

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

                 * Get file path.

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

                    return $path;

            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 (true !== $zip->open($fileName, ZIPARCHIVE::CREATE)) {

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

                            'linkhref' => true,

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

                    return array_merge($links, parent::getRecordRelatedListViewLinksLeftSide($viewModel));

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

                }

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

                        $fileSize = $fileSize + ($fileSize % 1024);

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

                            header('content-type: ' . $fileDetails['type']);

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

                            header('cache-control: private');

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

                    echo $fileContent;

            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 string

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

                            if (file_exists(ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $fileDetails['path'] . $fileDetails['attachmentsid'])) {

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

                            }

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

                        $documentModel = self::getInstanceById($recordId);

            Line exceeds 120 characters; contains 174 characters
            Open

                    return "javascript:Documents_Detail_Js.checkFileIntegrity('index.php?module=" . $this->getModuleName() . '&action=CheckFileIntegrity&record=' . $this->getId() . "')";

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

                        $this->fileDetails = (new \App\Db\Query())->from('vtiger_attachments')

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

                    return $this->fileDetails;

            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

                 */

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

                            }

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

                            'linkclass' => 'btn-sm btn-light',

            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 array

            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

                 * @param int[] $recordsIds

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

                        throw new \App\Exceptions\NoPermitted("cannot open <$fileName>");

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

                            'linktarget' => '_blank',

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

                    if ('I' === $this->get('filelocationtype') && ($fileDetails = $this->getFileDetails())) {

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

                            ->where(['crmid' => $this->get('id')])

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

                    $path = '';

            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 static function downloadFiles($recordsIds)

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

                    $fileName = $zipPath . "documentsZipFile_{$postfix}.zip";

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

                 * Check file integrity url.

            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

                        $filePath = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $path;

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

                            $fileName = $this->get('filename');

            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 ('I' === $this->get('filelocationtype')) {

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

                        $links['LBL_PREVIEW_FILE'] = Vtiger_Link_Model::getInstanceFromValues([

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

                        $savedFile = $fileDetails['path'] . $fileDetails['attachmentsid'];

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

                    return $returnValue;

            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 (file_exists(ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $fileDetails['path'] . $savedFile)) {

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

                 */

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

                    $postfix = time() . '_' . random_int(0, 1000);

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

                            'linktarget' => '_blank'

            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 ($this->get('return')) {

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

                        $fileName = $fileDetails['name'];

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

                            'linklabel' => 'LBL_PREVIEW_FILE',

            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

                    return "javascript:Documents_Detail_Js.checkFileIntegrity('index.php?module=" . $this->getModuleName() . '&action=CheckFileIntegrity&record=' . $this->getId() . "')";

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

                    }

            Line exceeds 120 characters; contains 130 characters
            Open

                            ->innerJoin('vtiger_seattachmentsrel', 'vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid')

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

                        $fileDetails = $this->getFileDetails();

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

                                'mimeType' => $fileDetails['type'],

            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 ($fileDetails = $this->getFileDetails()) {

            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

                 * Get file details.

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

                            header('pragma: 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

                {

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

                                $savedFile = $fileDetails['attachmentsid'] . '_' . $fileName;

            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

                            'linkicon' => 'fas fa-binoculars',

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

                    $zip->close();

            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 string

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

                                'path' => $filePath,

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

                    return 'index.php?module=Documents&action=UpdateDownloadCount&record=' . $this->getId();

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

                        $fileSize = filesize($filePath);

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

                 * @param string $fieldName

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

                                $path = $fileDetails['path'] . $savedFile;

            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 ('I' === $this->get('filelocationtype')) {

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

                        if ($fileDetails = $documentModel->getFileDetails()) {

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

                                if (file_exists($filePath . $fileDetails['attachmentsid'])) {

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

                        // If filename does not has the protocol prefix, default it to http://

            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

                /**

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

                public function updateFileStatus($status)

            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

                 * @param int $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

                                    ->setFieldValue('filedownloadcount', 0);

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

                                $file = [];

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

                                    $savedFile = $fileDetails['attachmentsid'];

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

                                    $documentModel->updateDownloadCount();

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

                    header('content-type: ' . \App\Fields\File::getMimeContentType($fileName));

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

                    header('accept-ranges: bytes');

            Line exceeds 120 characters; contains 151 characters
            Open

                    \App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filedownloadcount' => ++$downloadCount], ['notesid' => $notesId])->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

                        $this->set($fieldModel->getName(), $value);

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

                    }

            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

                 *

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

                public static function getReferenceModuleByDocId($record)

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

                public function isMandatorySave()

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

                        if (isset($this->file)) {

            Line exceeds 120 characters; contains 155 characters
            Open

                            if (UPLOAD_ERR_OK === $file['error'] && ($fileInstance = \App\Fields\File::loadFromRequest($file)) && $fileInstance->validateAndSecure()) {

            Line exceeds 120 characters; contains 190 characters
            Open

                                \App\Log::error("Error while saving a file, saving failed. | ID: {$this->getId()} | File: {$file['name']} | Error: " . \App\Fields\File::getErrorMessage($file['error']));

            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

                            ->setFieldValue('filetype', '')

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

                            $file['original_name'] = \App\Request::_get('0_hidden');

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

                    $result = false;

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

                    $fileInstance = \App\Fields\File::loadFromRequest($fileDetails);

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

                        'type' => $fileDetails['type'],

            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

                        $dataReader = (new \App\Db\Query())->select(['path', 'attachmentsid'])->from('vtiger_attachments')->where(['attachmentsid' => $attachmentsIds])->createCommand()->query();

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

                public function updateDownloadCount()

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

                    return \App\Layout\Icon::getIconByFileType($fileType);

            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 ($fieldModel) {

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

                        if (!empty($file['name']) && isset($file['error']) && $file['size'] > 0) {

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

                    if ('I' === $this->get('filelocationtype')) {

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

                            }

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

                        $db->createCommand()->delete('vtiger_attachments', ['attachmentsid' => $currentId])->execute();

            Line exceeds 120 characters; contains 182 characters
            Open

                        $dataReader = (new \App\Db\Query())->select(['path', 'attachmentsid'])->from('vtiger_attachments')->where(['attachmentsid' => $attachmentsIds])->createCommand()->query();

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

                            if (file_exists($fileName)) {

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

                        $dbCommand->delete('vtiger_attachments', ['attachmentsid' => $attachmentsIds])->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

                    readfile($fileName);

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

                    unlink($fileName);

            Line exceeds 120 characters; contains 142 characters
            Open

                    $downloadCount = (new \App\Db\Query())->select(['filedownloadcount'])->from('vtiger_notes')->where(['notesid' => $notesId])->scalar();

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

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

                    $db = \App\Db::getInstance();

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

                            ->setFieldValue('filesize', 0)

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

                    parent::saveToDb();

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

                 * This function is used to upload the attachment in the server and save that attachment information in db.

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

                    $this->ext['attachmentsName'] = $fileName = empty($fileDetails['original_name']) ? $fileDetails['name'] : $fileDetails['original_name'];

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

                    \App\Log::trace('Exiting uploadAndSaveFile');

            Line exceeds 120 characters; contains 287 characters
            Open

                    return (new App\Db\Query())->select(['vtiger_crmentity.setype'])->from('vtiger_crmentity')->innerJoin('vtiger_senotesrel', 'vtiger_senotesrel.crmid = vtiger_crmentity.crmid')->where(['vtiger_crmentity.deleted' => 0, 'vtiger_senotesrel.notesid' => $record])->distinct()->column();

            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 parent::isMandatorySave() || $_FILES;

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

                 * Sets field value for 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

                            if (UPLOAD_ERR_OK === $file['error'] && ($fileInstance = \App\Fields\File::loadFromRequest($file)) && $fileInstance->validateAndSecure()) {

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

                            $fileName = "http://$fileName";

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

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

                 */

            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

                    if (\App\Config::module($this->getModuleName(), 'storagePath')) {

            Line exceeds 120 characters; contains 154 characters
            Open

                    $attachmentsIds = (new \App\Db\Query())->select(['attachmentsid'])->from('vtiger_seattachmentsrel')->where(['crmid' => $this->getId()])->column();

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

                                    $savedFile = $fileDetails['attachmentsid'] . '_' . html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));

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

                                if (file_exists($filePath . $savedFile)) {

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

                }

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

                 * Update file status.

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

                 * @return array

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

                 * @param mixed  $value

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

                                \App\Log::error("Error while saving a file, saving failed. | ID: {$this->getId()} | File: {$file['name']} | Error: " . \App\Fields\File::getErrorMessage($file['error']));

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

                                $this->file = [];

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

                        $db->createCommand()->delete('vtiger_seattachmentsrel', ['crmid' => $this->getId()])->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

                                unlink($fileName);

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

                            }

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

                        $db->createCommand()->insert('vtiger_seattachmentsrel', ['crmid' => $id, 'attachmentsid' => $currentId])->execute();

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

                        $this->ext['attachmentsId'] = $currentId;

            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="' . basename($fileName) . '";');

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

                 */

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

                    App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filestatus' => $status], ['notesid' => $this->get('id')])->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

                }

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

                    $fileNameByField = 'filename';

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

                            $file = $this->file;

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

                                    ->setFieldValue('filesize', $fileInstance->getSize())

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

                public function uploadAndSaveFile($fileDetails)

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

                    \App\Log::trace("Entering into uploadAndSaveFile($id,$moduleName) method.");

            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

                    $dbCommand = \App\Db::getInstance()->createCommand();

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

                        $dataReader->close();

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

                                    $zip->addFile($filePath . $savedFile, basename($documentModel->get('filename')));

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

                                }

            Line exceeds 120 characters; contains 142 characters
            Open

                    App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filestatus' => $status], ['notesid' => $this->get('id')])->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

                    \App\Db::getInstance()->createCommand()->update('vtiger_notes', ['filedownloadcount' => ++$downloadCount], ['notesid' => $notesId])->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

                 * @return $this

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

                                    ->setFieldValue('filetype', $fileInstance->getMimeType())

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

                    $uploadFilePath = \App\Fields\File::initStorageFileDirectory($moduleName);

            Line exceeds 120 characters; contains 128 characters
            Open

                        $db->createCommand()->insert('vtiger_seattachmentsrel', ['crmid' => $id, 'attachmentsid' => $currentId])->execute();

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

                        while ($row = $dataReader->read()) {

            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

                    $notesId = $this->get('id');

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

                public function setFieldValue(string $fieldName, $value)

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

                    $downloadCount = (new \App\Db\Query())->select(['filedownloadcount'])->from('vtiger_notes')->where(['notesid' => $notesId])->scalar();

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

                    return $this;

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

                 *

            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

                {

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

                        // Protocol prefix could be like (https://, smb://, file://, \\, smb:\\,...)

            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

                            $file = $_FILES[$fileNameByField] ?? [];

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

                            ->setFieldValue('filedownloadcount', null);

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

                            $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

                        if (!empty($fileName) && !preg_match('/^\w{1,5}:\/\/|^\w{0,3}:?\\\\\\\\/', trim($fileName), $match)) {

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

                        $this->setFieldValue('filename', $fileName)

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

                    $id = $this->getId();

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

                    $currentId = $db->getLastInsertID('vtiger_attachments_attachmentsid_seq');

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

                public function delete()

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

                    if (!empty($attachmentsIds)) {

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

                    if ($fileInstance->moveFile($destinyFilePath)) {

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

                        $db->createCommand()->delete('vtiger_seattachmentsrel', ['crmid' => $id])->execute();

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

                        $result = true;

            Line exceeds 120 characters; contains 166 characters
            Open

                                    $savedFile = $fileDetails['attachmentsid'] . '_' . html_entity_decode($fileDetails['name'], ENT_QUOTES, \App\Config::main('default_charset'));

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

                public static function getFileIconByFileType($fileType)

            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

                {

            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

                                $this->setFieldValue('filename', \App\Purifier::decodeHtml(App\Purifier::purify($file['name'])))

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

                    } elseif ('E' === $this->get('filelocationtype')) {

            Line exceeds 120 characters; contains 144 characters
            Open

                    $this->ext['attachmentsName'] = $fileName = empty($fileDetails['original_name']) ? $fileDetails['name'] : $fileDetails['original_name'];

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

                 * Get download count update url.

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

                    $db = \App\Db::getInstance();

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

                 * Get reference module by doc id.

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

                 * Function to save record.

            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

                }

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

                    $moduleName = $this->getModuleName();

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

                        'path' => $uploadFilePath

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

                    }

            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

                    return $result;

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

                    header('content-length: ' . filesize($fileName));

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

                 * @param int $status

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

                public function getDownloadCountUpdateUrl()

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

                    return (new App\Db\Query())->select(['vtiger_crmentity.setype'])->from('vtiger_crmentity')->innerJoin('vtiger_senotesrel', 'vtiger_senotesrel.crmid = vtiger_crmentity.crmid')->where(['vtiger_crmentity.deleted' => 0, 'vtiger_senotesrel.notesid' => $record])->distinct()->column();

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

                {

            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

                        }

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

                        $fileName = $this->get($fileNameByField);

            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

                 * Update download count.

            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->getField($fieldName);

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

                        $this->setDataForSave([$fieldModel->getTableName() => [$fieldModel->getColumnName() => $value]]);

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

                    //Inserting into attachments table

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

                            if ($this->uploadAndSaveFile($file) && isset($this->file)) {

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

                 * @param array $fileDetails - array which contains the file information(name, type, size, tmp_name and error)

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

                 * @return bool

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

                    $db->createCommand()->insert('vtiger_attachments', [

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

                        'name' => ltrim(App\Purifier::purify($fileName)),

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

                    $attachmentsIds = (new \App\Db\Query())->select(['attachmentsid'])->from('vtiger_seattachmentsrel')->where(['crmid' => $this->getId()])->column();

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

                        $destinyFilePath = $uploadFilePath . $currentId;

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

                        $destinyFilePath = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . $uploadFilePath . $currentId;

            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

                    parent::delete();

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

                            $fileName = $row['path'] . $row['attachmentsid'];

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

            class Documents_Record_Model extends Vtiger_Record_Model

            There are no issues that match your filters.

            Category
            Status