YetiForceCompany/YetiForceCRM

View on GitHub
app/Integrations/SMSProvider.php

Summary

Maintainability
A
0 mins
Test Coverage
F
20%

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

        $iterator = new \DirectoryIterator(__DIR__ . '/SMSProvider');
Severity: Minor
Found in app/Integrations/SMSProvider.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 '106', column '16').
Open

        $data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['id' => $id])->one();
Severity: Minor
Found in app/Integrations/SMSProvider.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 '93', column '16').
Open

        $data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['isactive' => self::STATUS_ACTIVE])->one();
Severity: Minor
Found in app/Integrations/SMSProvider.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 '\App\Json' in method 'getProviderByData'.
Open

        $parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
Severity: Minor
Found in app/Integrations/SMSProvider.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\Json' in method 'getProviderByData'.
Open

        $parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
Severity: Minor
Found in app/Integrations/SMSProvider.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 assigning values to variables in if clauses and the like (line '37', column '105').
Open

    public static function getProviders(): array
    {
        $providers = [];
        $iterator = new \DirectoryIterator(__DIR__ . '/SMSProvider');
        foreach ($iterator as $item) {
Severity: Minor
Found in app/Integrations/SMSProvider.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

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

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

        $parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
Severity: Critical
Found in app/Integrations/SMSProvider.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 undeclared method \App\Db\Query::from
Open

        $data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['id' => $id])->one();
Severity: Critical
Found in app/Integrations/SMSProvider.php by phan

Call to undeclared method \App\Db\Query::from
Open

        $data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['isactive' => self::STATUS_ACTIVE])->one();
Severity: Critical
Found in app/Integrations/SMSProvider.php by phan

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

    public static function getById(int $id): ?SMSProvider\Provider
Severity: Minor
Found in app/Integrations/SMSProvider.php by phpmd

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

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

    /** @var int Status active */

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

        $iterator = new \DirectoryIterator(__DIR__ . '/SMSProvider');

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 SMSProvider\Provider|null

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

    public static function getProviderByData(array $data): ?SMSProvider\Provider

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

     * Check if there is an active provider.

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 static function getProviderByName(string $name): ?SMSProvider\Provider

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

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 static function getProviders(): array

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

    {

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

     * Get provider by data.

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

        return $data ? self::getProviderByData($data) : null;

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

        $providers = [];

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

        foreach ($parameters as $name => $value) {

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 null !== static::getDefaultProvider();

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

    public const STATUS_ACTIVE = 1;

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

        }

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

     * Get provider by name.

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

     * @return SMSProvider\Provider|null

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

        $className = "\\App\\Integrations\\SMSProvider\\{$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

        return class_exists($className) ? new $className() : null;

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

        unset($data['parameters']);

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

    public static function isActiveProvider(): bool

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 $data ? self::getProviderByData($data) : null;

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

    /** @var int Status inactive */

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

        $parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];

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

            $data[$name] = $value;

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

     * @return SMSProvider\Provider|null

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

     * @return SMSProvider\Provider|null

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

    }

Line exceeds 120 characters; contains 179 characters
Open

            if ($item->isFile() && 'Provider.php' !== $item->getFilename() && 'php' === $item->getExtension() && $provider = self::getProviderByName($item->getBasename('.php'))) {

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

                $providers[$provider->getName()] = $provider;

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

     * @param string $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

     */

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

     * Get default provider.

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 const TABLE_NAME = 'a_#__smsnotifier_servers';

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

        return $providers;

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

     * @param array $data

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

    public const STATUS_INACTIVE = 0;

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

        foreach ($iterator as $item) {

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

        $data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['isactive' => self::STATUS_ACTIVE])->one();

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

     * @param int $id

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

    public static function getById(int $id): ?SMSProvider\Provider

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

     * Get providers.

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

     * @return bool

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

    public static function getDefaultProvider(): ?SMSProvider\Provider

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

     *

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

        $provider = self::getProviderByName($data['providertype']);

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

     */

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

        $data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['id' => $id])->one();

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 ($item->isFile() && 'Provider.php' !== $item->getFilename() && 'php' === $item->getExtension() && $provider = self::getProviderByName($item->getBasename('.php'))) {

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

        return $provider ? $provider->setData($data) : null;

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

     * Get provider by ID.

There are no issues that match your filters.

Category
Status