YetiForceCompany/YetiForceCRM

View on GitHub
modules/MailIntegration/views/MessageCompose.php

Summary

Maintainability
B
5 hrs
Test Coverage
F
0%

Missing class import via use statement (line '40', column '8').
Open

            new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

MissingImport

Since: 2.7.0

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

Example

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

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

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

            new \App\Exceptions\NoPermitted('ERR_PAID_FUNCTIONALITY||YetiForceOutlook', 406);

MissingImport

Since: 2.7.0

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

Example

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

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

Missing class import via use statement (line '60', column '8').
Open

            new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

MissingImport

Since: 2.7.0

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

Example

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

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

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

        } else {
            $viewer = $this->getViewer($request);
            $viewer->view('MessageCompose.tpl', $moduleName);
        }

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\YetiForce\Register' in method 'checkPermission'.
Open

        if ((explode('-', $request->getByType('query', 'AlnumExtended'))[0] ?? '') !== substr(\App\YetiForce\Register::getInstanceKey(), 0, 30)) {

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

        if (!\App\User::getCurrentUserId()) {

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

            \App\Log::error("Incorrect integration key: {$request->getByType('query', 'AlnumExtended')}.");

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::error("No access to the module: {$id}.");

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

            $viewer->assign('MESSAGE', \App\Language::translate($this->error));

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

            $viewer->assign('HEADER_MESSAGE', \App\Language::translate('LBL_ERROR'));

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

            $id = \App\User::getCurrentUserRealId();

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

            $this->error = 'LBL_PERMISSION_DENIED';

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 getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

        if (!\App\User::getCurrentUserId()) {

Call to method getInstanceKey from undeclared class \App\YetiForce\Register
Open

        if ((explode('-', $request->getByType('query', 'AlnumExtended'))[0] ?? '') !== substr(\App\YetiForce\Register::getInstanceKey(), 0, 30)) {

Return type of getFooterScripts() is undeclared type \App\Controller\View\Vtiger_JsScript_Model[]
Open

    public function getFooterScripts(App\Request $request)

Return type of getHeaderScripts() is undeclared type \App\Controller\View\Vtiger_JsScript_Model[]
Open

    public function getHeaderScripts(App\Request $request)

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('MESSAGE_EXPANDED', false);

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

            \App\Log::error("Incorrect integration key: {$request->getByType('query', 'AlnumExtended')}.");

Call to method getCurrentUserRealId from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            $id = \App\User::getCurrentUserRealId();

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('HEADER_MESSAGE', \App\Language::translate('LBL_ERROR'));

Reference to static property frameBreaker from undeclared class \CsrfMagic\Csrf
Open

        \CsrfMagic\Csrf::$frameBreaker = \Config\Security::$csrfFrameBreaker = false;

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

            \App\Log::error("No access to the module: {$id}.");

Argument 1 (mixed) is string but \Users_Privileges_Model::hasModulePermission() takes int defined at /code/modules/Users/models/Privileges.php:101
Open

        } elseif (!Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($moduleName)) {

Call to undeclared method \Vtiger_Viewer::assign
Open

            $viewer->assign('MESSAGE', \App\Language::translate($this->error));

Either remove this useless object instantiation of class "\App\Exceptions\NoPermitted" or use it
Open

            new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

There is no good reason to create a new object to not do anything with it. Most of the time, this is due to a missing piece of code and so could lead to an unexpected behavior in production.

If it was done on purpose because the constructor has side-effects, then that side-effect code should be moved into a separate, static method and called directly.

Noncompliant Code Example

if ($x < 0) {
  new foo;  // Noncompliant
}

Compliant Solution

$var = NULL;
if ($x < 0) {
  $var = new foo;
}

Either remove this useless object instantiation of class "\App\Exceptions\NoPermitted" or use it
Open

            new \App\Exceptions\NoPermitted('ERR_PAID_FUNCTIONALITY||YetiForceOutlook', 406);

There is no good reason to create a new object to not do anything with it. Most of the time, this is due to a missing piece of code and so could lead to an unexpected behavior in production.

If it was done on purpose because the constructor has side-effects, then that side-effect code should be moved into a separate, static method and called directly.

Noncompliant Code Example

if ($x < 0) {
  new foo;  // Noncompliant
}

Compliant Solution

$var = NULL;
if ($x < 0) {
  $var = new foo;
}

Either remove this useless object instantiation of class "\App\Exceptions\NoPermitted" or use it
Open

            new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

There is no good reason to create a new object to not do anything with it. Most of the time, this is due to a missing piece of code and so could lead to an unexpected behavior in production.

If it was done on purpose because the constructor has side-effects, then that side-effect code should be moved into a separate, static method and called directly.

Noncompliant Code Example

if ($x < 0) {
  new foo;  // Noncompliant
}

Compliant Solution

$var = NULL;
if ($x < 0) {
  $var = new foo;
}

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

    public function checkPermission(App\Request $request)
    {
        if ((explode('-', $request->getByType('query', 'AlnumExtended'))[0] ?? '') !== substr(\App\YetiForce\Register::getInstanceKey(), 0, 30)) {
            $this->error = 'LBL_PERMISSION_DENIED';
            \App\Log::error("Incorrect integration key: {$request->getByType('query', 'AlnumExtended')}.");
Severity: Major
Found in modules/MailIntegration/views/MessageCompose.php and 1 other location - About 4 hrs to fix
modules/MailIntegration/views/MessageDetail.php on lines 35..47

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

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 (!\App\User::getCurrentUserId()) {
            $viewer = $this->getViewer($request);
            $viewer->view('LoginIframe.tpl', $moduleName);
        } elseif (!Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($moduleName)) {
            $this->error = 'LBL_PERMISSION_DENIED';
Severity: Minor
Found in modules/MailIntegration/views/MessageCompose.php and 1 other location - About 55 mins to fix
modules/MailIntegration/views/MessageDetail.php on lines 53..61

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

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 MailIntegration_MessageCompose_View extends \App\Controller\View\Base

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

            $id = \App\User::getCurrentUserRealId();

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

The class MailIntegration_MessageCompose_View is not named in CamelCase.
Open

class MailIntegration_MessageCompose_View extends \App\Controller\View\Base
{
    /**
     * Error message.
     *

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

     * Error message.

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

        \CsrfMagic\Csrf::$frameBreaker = \Config\Security::$csrfFrameBreaker = false;

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

            $id = \App\User::getCurrentUserRealId();

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

    protected $error;

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

    public function checkPermission(App\Request $request)

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

            $this->error = 'LBL_PERMISSION_DENIED';

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

        if (!\App\User::getCurrentUserId()) {

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

            'https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js',

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

    /**

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

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

    public function loginRequired()

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

        $moduleName = $request->getModule();

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

        } elseif (!Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($moduleName)) {

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

    /** {@inheritdoc} */

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

            $viewer->assign('MESSAGE_EXPANDED', false);

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

            "modules.{$request->getModule()}.resources.{$request->getByType('source')}{$request->getByType('view')}",

Line exceeds 120 characters; contains 146 characters
Open

        if ((explode('-', $request->getByType('query', 'AlnumExtended'))[0] ?? '') !== substr(\App\YetiForce\Register::getInstanceKey(), 0, 30)) {

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

            \App\Log::error("Incorrect integration key: {$request->getByType('query', 'AlnumExtended')}.");

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

        if ((explode('-', $request->getByType('query', 'AlnumExtended'))[0] ?? '') !== substr(\App\YetiForce\Register::getInstanceKey(), 0, 30)) {

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->error = 'LBL_PERMISSION_DENIED';

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

            $this->error = 'LBL_PERMISSION_DENIED';

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

     * @var string

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

     */

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

    {

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

    {

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

            $viewer = $this->getViewer($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

        return array_merge(parent::getHeaderScripts($request), $this->checkAndConvertJsScripts([

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

            new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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

            $viewer->view('LoginIframe.tpl', $moduleName);

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

            $viewer->assign('MESSAGE', \App\Language::translate($this->error));

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

    public function getFooterScripts(App\Request $request)

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

        if ('outlook' !== $request->getByType('source')) {

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

            $viewer->view('Exceptions/ExceptionError.tpl', 'Vtiger');

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

            $viewer->assign('HEADER_MESSAGE', \App\Language::translate('LBL_ERROR'));

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

            $viewer = $this->getViewer($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

            new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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

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

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

            $viewer->view('MessageCompose.tpl', $moduleName);

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

            new \App\Exceptions\NoPermitted('ERR_PAID_FUNCTIONALITY||YetiForceOutlook', 406);

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

            \App\Log::error("No access to the module: {$id}.");

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

        ]));

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

        return array_merge(parent::getFooterScripts($request), $this->checkAndConvertJsScripts([

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

        ]));

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

class MailIntegration_MessageCompose_View extends \App\Controller\View\Base

There are no issues that match your filters.

Category
Status