YetiForceCompany/YetiForceCRM

View on GitHub
modules/SMSNotifier/crons/SMSNotifier.php

Summary

Maintainability
A
35 mins
Test Coverage
F
14%

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

    public function process()
    {
        if (\App\Integrations\SMSProvider::isActiveProvider()) {
            $queryGenerator = new \App\QueryGenerator($this->moduelName);
            $dataReader = $queryGenerator->setFields(['id'])
Severity: Minor
Found in modules/SMSNotifier/crons/SMSNotifier.php - About 35 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

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

            $queryGenerator = new \App\QueryGenerator($this->moduelName);

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

                ->setLimit(\App\Config::module($this->moduelName, 'maxCronSentSMS'))

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

                $recordModel = \SMSNotifier_Record_Model::getInstanceById($recordId, $this->moduelName);

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\Integrations\SMSProvider' in method 'process'.
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

Remove this unused "STATUS_QUEUE" private field.
Open

    private const STATUS_QUEUE = 'PLL_QUEUE';

If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

Noncompliant Code Example

class MyClass {
  private $foo = 4;                       //foo is unused

  public function compute($a) {
    return $a * 4;
  }
}

Compliant Solution

class MyClass {

  public function compute($a) {
    return $a * 4;
  }
}

See

Call to method setFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            $dataReader = $queryGenerator->setFields(['id'])
Severity: Critical
Found in modules/SMSNotifier/crons/SMSNotifier.php by phan

Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            $queryGenerator = new \App\QueryGenerator($this->moduelName);
Severity: Critical
Found in modules/SMSNotifier/crons/SMSNotifier.php by phan

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

class SMSNotifier_SMSNotifier_Cron extends \App\CronHandler

The class SMSNotifier_SMSNotifier_Cron is not named in CamelCase.
Open

class SMSNotifier_SMSNotifier_Cron extends \App\CronHandler
{
    /** @var string Status */
    private const STATUS_QUEUE = 'PLL_QUEUE';
    /** @var string Module name */

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

                $recordModel->send();

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

    public function process()

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

            $dataReader = $queryGenerator->setFields(['id'])

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

            while ($recordId = $dataReader->readColumn(0)) {

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

            $queryGenerator = new \App\QueryGenerator($this->moduelName);

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

                $recordModel = \SMSNotifier_Record_Model::getInstanceById($recordId, $this->moduelName);

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

                }

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

    /** {@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

    private const STATUS_QUEUE = 'PLL_QUEUE';

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

    private $moduelName = 'SMSNotifier';

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

            }

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

                ->createQuery()

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

    /** @var string Module name */

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->updateLastActionTime();

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

                ->setLimit(\App\Config::module($this->moduelName, 'maxCronSentSMS'))

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

    /** @var string Status */

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

                ->addCondition('smsnotifier_status', static::STATUS_QUEUE, 'e')

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

                ->createCommand()->query();

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

                if ($this->checkTimeout()) {

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

                    break;

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

class SMSNotifier_SMSNotifier_Cron extends \App\CronHandler

There are no issues that match your filters.

Category
Status