YetiForceCompany/YetiForceCRM

View on GitHub
modules/SMSNotifier/workflow/SMSTask.php

Summary

Maintainability
A
45 mins
Test Coverage
F
0%

Function doTask has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        if (\App\Integrations\SMSProvider::isActiveProvider()) {
            $moduleName = 'SMSNotifier';
            $recordModelTemp = \Vtiger_Record_Model::getCleanInstance($moduleName)->set('message', $this->content);
Severity: Minor
Found in modules/SMSNotifier/workflow/SMSTask.php - About 45 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

Avoid using static access to class '\App\Integrations\SMSProvider' in method 'doTask'.
Open

        if (\App\Integrations\SMSProvider::isActiveProvider()) {

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\TextParser' in method 'doTask'.
Open

            $textParser = \App\TextParser::getInstanceByModel($recordModel);

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

Argument 2 (callback) is Closure():'' but \preg_replace_callback() takes callable(array):string
Open

                $phoneNumber = preg_replace_callback('/[^\d\+]/s', function () {

Reference to undeclared property \VTSMSTask->sms_recepient
Open

            $recepient = $textParser->setContent($this->sms_recepient)->parse()->getContent();

Call to method getInstanceByModel from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
Open

            $textParser = \App\TextParser::getInstanceByModel($recordModel);
Severity: Critical
Found in modules/SMSNotifier/workflow/SMSTask.php by phan

Saw unextractable annotation for comment '/** @var array Fields */'
Open

    /** @var array Fields */

Reference to undeclared property \VTSMSTask->content (Did you mean expr->contents)
Open

            $recordModelTemp = \Vtiger_Record_Model::getCleanInstance($moduleName)->set('message', $this->content);

Call to undeclared method \App\Base::save
Open

                    $recordModel->set('phone', $phoneNumber)->save();
Severity: Critical
Found in modules/SMSNotifier/workflow/SMSTask.php by phan

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

class VTSMSTask extends VTTask

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

                $phoneNumber = preg_replace_callback('/[^\d\+]/s', function () {

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 bool Execute Immediately */

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

    /** @var array Fields */

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

    public function getFieldNames()

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

     *

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

            $recepient = $textParser->setContent($this->sms_recepient)->parse()->getContent();

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

                }, strip_tags($phoneNumber));

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 doTask($recordModel)

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

                $recordModelTemp->set('related_to', $recordModel->getId());

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

            $textParser = \App\TextParser::getInstanceByModel($recordModel);

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

                    $recordModel->set('phone', $phoneNumber)->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

            $moduleName = 'SMSNotifier';

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

            $recepients = array_unique(explode(',', $recepient));

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 Vtiger_Record_Model $recordModel

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

            $recordModelTemp = \Vtiger_Record_Model::getCleanInstance($moduleName)->set('message', $this->content);

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

            foreach ($recepients as $phoneNumber) {

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

            if (\in_array($recordModel->getModuleName(), $recordModelTemp->getField('related_to')->getReferenceList())) {

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

                    return '';

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

                if ($phoneNumber) {

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

        return ['content', 'sms_recepient'];

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

                    $recordModel = clone $recordModelTemp;

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

    public $executeImmediately = true;

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

        if (\App\Integrations\SMSProvider::isActiveProvider()) {

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

Line exceeds 120 characters; contains 121 characters
Open

            if (\in_array($recordModel->getModuleName(), $recordModelTemp->getField('related_to')->getReferenceList())) {

There are no issues that match your filters.

Category
Status