YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Roles/actions/UploadLogo.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

process accesses the super-global variable $_FILES.
Open

    public function process(App\Request $request)
    {
        $targetFile = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'Logo' . DIRECTORY_SEPARATOR . 'logo';
        $response = new Vtiger_Response();
        $result = ['success' => false, 'message' => \App\Language::translate('LBL_UPLOAD_ERROR', $request->getModule(false))];

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

process accesses the super-global variable $_FILES.
Open

    public function process(App\Request $request)
    {
        $targetFile = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'Logo' . DIRECTORY_SEPARATOR . 'logo';
        $response = new Vtiger_Response();
        $result = ['success' => false, 'message' => \App\Language::translate('LBL_UPLOAD_ERROR', $request->getModule(false))];

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 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $targetFile = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'Logo' . DIRECTORY_SEPARATOR . 'logo';
        $response = new Vtiger_Response();
        $result = ['success' => false, 'message' => \App\Language::translate('LBL_UPLOAD_ERROR', $request->getModule(false))];
Severity: Minor
Found in modules/Settings/Roles/actions/UploadLogo.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

Missing class import via use statement (line '16', column '19').
Open

        $response = new Vtiger_Response();

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

Avoid using static access to class '\App\Fields\File' in method 'process'.
Open

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

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

            if ($fileInstance->validateAndSecure('image') && $fileInstance->getSize() < \App\Config::getMaxUploadSize()) {

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\Language' in method 'process'.
Open

        $result = ['success' => false, 'message' => \App\Language::translate('LBL_UPLOAD_ERROR', $request->getModule(false))];

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\Language' in method 'process'.
Open

                    $result = ['success' => true, 'message' => \App\Language::translate('LBL_UPLOAD_SUCCESS', $request->getModule(false))];

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

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

class Settings_Roles_UploadLogo_Action extends Settings_Vtiger_Index_Action

The class Settings_Roles_UploadLogo_Action is not named in CamelCase.
Open

class Settings_Roles_UploadLogo_Action extends Settings_Vtiger_Index_Action
{
    /** {@inheritdoc} */
    public function process(App\Request $request)
    {

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

                    $result = ['success' => true, 'message' => \App\Language::translate('LBL_UPLOAD_SUCCESS', $request->getModule(false))];

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

        $targetFile = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'Logo' . DIRECTORY_SEPARATOR . 'logo';

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

        }

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

        $result = ['success' => false, 'message' => \App\Language::translate('LBL_UPLOAD_ERROR', $request->getModule(false))];

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

                    unlink($targetFile);

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

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

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

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

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

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

        $response = new Vtiger_Response();

Line exceeds 120 characters; contains 139 characters
Open

                    $result = ['success' => true, 'message' => \App\Language::translate('LBL_UPLOAD_SUCCESS', $request->getModule(false))];

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

        if (!empty($_FILES['role_logo'])) {

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

            if ($fileInstance->validateAndSecure('image') && $fileInstance->getSize() < \App\Config::getMaxUploadSize()) {

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

        $response->setResult($result);

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

        $response->emit();

Line exceeds 120 characters; contains 126 characters
Open

        $result = ['success' => false, 'message' => \App\Language::translate('LBL_UPLOAD_ERROR', $request->getModule(false))];

Line exceeds 120 characters; contains 122 characters
Open

            if ($fileInstance->validateAndSecure('image') && $fileInstance->getSize() < \App\Config::getMaxUploadSize()) {

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

    public function process(App\Request $request)

Line exceeds 120 characters; contains 207 characters
Open

        $targetFile = ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'Logo' . DIRECTORY_SEPARATOR . 'logo';

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

    }

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

class Settings_Roles_UploadLogo_Action extends Settings_Vtiger_Index_Action

There are no issues that match your filters.

Category
Status