YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/PDF/views/Import.php

Summary

Maintainability
B
5 hrs
Test Coverage
F
0%

process accesses the super-global variable $_FILES.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);
Severity: Minor
Found in modules/Settings/PDF/views/Import.php by phpmd

Superglobals

Since: 0.2

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

Example

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

Source

Function process has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);
Severity: Minor
Found in modules/Settings/PDF/views/Import.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

Method process has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        \App\Log::trace('Start ' . __METHOD__);
        $qualifiedModule = $request->getModule(false);
        $viewer = $this->getViewer($request);
Severity: Major
Found in modules/Settings/PDF/views/Import.php - About 2 hrs to fix

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

        public function process(App\Request $request)
        {
            \App\Log::trace('Start ' . __METHOD__);
            $qualifiedModule = $request->getModule(false);
            $viewer = $this->getViewer($request);
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 25 to the 15 allowed.
    Open

        public function process(App\Request $request)
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.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 '59', column '16').
    Open

                        throw new \App\Exceptions\Security('ERR_ILLEGAL_WATERMARK_IMAGE');
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 '21', column '15').
    Open

                    throw new \App\Exceptions\Security('ERR_ILLEGAL_FILE');
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'Settings_PDF_Record_Model' in method 'process'.
    Open

                $pdfModel = Settings_PDF_Record_Model::getCleanInstance();
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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\Log' in method 'process'.
    Open

            \App\Log::trace('Start ' . __METHOD__);
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'Settings_PDF_Record_Model' in method 'process'.
    Open

                Settings_PDF_Record_Model::save($pdfModel, 'import');
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'process'.
    Open

                    $imageInstance = \App\Fields\File::loadFromInfo([
                        'content' => base64_decode($base64Image),
                        'path' => $imagePath,
                        'name' => 'watermark_image',
                        'validateAllCodeInjection' => true,
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'Settings_PDF_Record_Model' in method 'process'.
    Open

                    Settings_PDF_Record_Model::save($pdfModel, 8);
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'process'.
    Open

                $fileInstance = \App\Fields\File::loadFromRequest($_FILES['imported_xml']);
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'process'.
    Open

                                    $pdfModel->set($columnKey, App\Purifier::purifyHtml((string) $columnValue));
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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\Log' in method 'process'.
    Open

            \App\Log::trace('End ' . __METHOD__);
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.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 'process'.
    Open

                                    $pdfModel->set($columnKey, App\Purifier::purify((string) $columnValue));
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

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

                                case 'watermark_image':
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.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.

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

            \App\Log::trace('End ' . __METHOD__);
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('UPLOAD', true);
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.php by phan

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

            \App\Log::trace('Start ' . __METHOD__);
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.php by phan

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('RECORDID', $pdfModel->getId());
    Severity: Critical
    Found in modules/Settings/PDF/views/Import.php by phan

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

    class Settings_PDF_Import_View extends Settings_Vtiger_Index_View

    The class Settings_PDF_Import_View is not named in CamelCase.
    Open

    class Settings_PDF_Import_View extends Settings_Vtiger_Index_View
    {
        public function process(App\Request $request)
        {
            \App\Log::trace('Start ' . __METHOD__);
    Severity: Minor
    Found in modules/Settings/PDF/views/Import.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

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

                            switch ($columnKey) {

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

                                    $imagePath = (string) $columnValue;

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

            \App\Log::trace('Start ' . __METHOD__);

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

                if (!$fileInstance->validate() || 'xml' !== $fileInstance->getExtension(true)) {

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

            $viewer = $this->getViewer($request);

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

                    throw new \App\Exceptions\Security('ERR_ILLEGAL_FILE');

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

                $imagePath = '';

    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 process(App\Request $request)

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

        {

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

                $base64Image = false;

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

                                    $base64Image = (string) $columnValue;

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

            $qualifiedModule = $request->getModule(false);

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

                                    break;

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

                Settings_PDF_Record_Model::save($pdfModel, 'import');

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

                $pdfModel = Settings_PDF_Record_Model::getCleanInstance();

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

                $xml = simplexml_load_file($fileInstance->getPath());

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

                                    $pdfModel->set($columnKey, App\Purifier::purifyHtml((string) $columnValue));

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

                $fileInstance = \App\Fields\File::loadFromRequest($_FILES['imported_xml']);

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

                    foreach ($fieldsValue as $fieldValue) {

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

                                case 'watermark_image':

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

                                    $pdfModel->set($columnKey, App\Purifier::purify((string) $columnValue));

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

                        'path' => $imagePath,

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

                    ]);

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

                $viewer->assign('UPLOAD', true);

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

                                case 'header_content':

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

                    $imageInstance = \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

                                case 'body_content':

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

                    }

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

                    $targetDir = Settings_PDF_Module_Model::$uploadPath;

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

                    }

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

                    $pdfModel->set('watermark_image', $newFilePath);

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

                $viewer->assign('RECORDID', $pdfModel->getId());

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

                }

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

            $viewer->assign('QUALIFIED_MODULE', $qualifiedModule);

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

        }

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

                                default:

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

            }

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

                                case 'imageblob':

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

                                    break;

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

                        'content' => base64_decode($base64Image),

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

            return array_merge($this->checkAndConvertCssStyles([

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

        }

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

                        foreach ($fieldValue as $columnKey => $columnValue) {

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

                                    break;

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

                        'name' => 'watermark_image',

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

                        throw new \App\Exceptions\Security('ERR_ILLEGAL_WATERMARK_IMAGE');

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

                    $newFilePath = $targetDir . $pdfModel->getId() . '.' . $imageInstance->getExtension();

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

                'modules.Settings.' . $request->getModule() . '.Edit',

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

                foreach ($xml as $fieldsValue) {

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

                                case 'footer_content':

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

                if ($pdfModel->getId() && $imagePath && $base64Image) {

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

                    Settings_PDF_Record_Model::save($pdfModel, 8);

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

                }

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

            if ($request->has('upload') && $request->getBoolean('upload')) {

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

                                    $pdfModel->set($columnKey, '');

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

                        'validateAllCodeInjection' => true,

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

            \App\Log::trace('End ' . __METHOD__);

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

                    if (!$imageInstance->validateAndSecure('image')) {

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

                    file_put_contents($newFilePath, $imageInstance->getContents());

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

            ]), parent::getHeaderCss($request));

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

        public function getHeaderCss(App\Request $request)

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

        {

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

            $viewer->view('Import.tpl', $qualifiedModule);

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

    class Settings_PDF_Import_View extends Settings_Vtiger_Index_View

    There are no issues that match your filters.

    Category
    Status