YetiForceCompany/YetiForceCRM

View on GitHub
app/Fields/Country.php

Summary

Maintainability
A
35 mins
Test Coverage
F
38%

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

    public static function findCountryName(string $value): string
    {
        if (empty($value)) {
            return '';
        }
Severity: Minor
Found in app/Fields/Country.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

The method getAll has a boolean flag argument $type, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function getAll($type = false)
Severity: Minor
Found in app/Fields/Country.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

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

        $query = new \App\Db\Query();
Severity: Minor
Found in app/Fields/Country.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\Language' in method 'findCountryName'.
Open

}
Severity: Minor
Found in app/Fields/Country.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\Cache' in method 'getAll'.
Open

            return \App\Cache::get('Country|getAll', $type);
Severity: Minor
Found in app/Fields/Country.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 '81', column '8').
Open

    public static function findCountryName(string $value): string
    {
        if (empty($value)) {
            return '';
        }
Severity: Minor
Found in app/Fields/Country.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

Avoid using static access to class '\App\Cache' in method 'getAll'.
Open

        \App\Cache::save('Country|getAll', $type, $rows);
Severity: Minor
Found in app/Fields/Country.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\Language' in method 'findCountryName'.
Open

        if (($userLanguage = \App\Language::getLanguage()) !== ($defaultLanguage = \App\Config::main('default_language'))) {
Severity: Minor
Found in app/Fields/Country.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\Language' in method 'findCountryName'.
Open

}
Severity: Minor
Found in app/Fields/Country.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\Cache' in method 'getAll'.
Open

        if (\App\Cache::has('Country|getAll', $type)) {
Severity: Minor
Found in app/Fields/Country.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 '81', column '59').
Open

    public static function findCountryName(string $value): string
    {
        if (empty($value)) {
            return '';
        }
Severity: Minor
Found in app/Fields/Country.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

Avoid using static access to class '\App\Config' in method 'findCountryName'.
Open

        if (($userLanguage = \App\Language::getLanguage()) !== ($defaultLanguage = \App\Config::main('default_language'))) {
Severity: Minor
Found in app/Fields/Country.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

Define a constant instead of duplicating this literal "Country|getAll" 3 times.
Open

        if (\App\Cache::has('Country|getAll', $type)) {
Severity: Critical
Found in app/Fields/Country.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::select
Open

        $query->select($select)->from('u_#__countries')->where(['status' => 0])->orderBy('sortorderid');
Severity: Critical
Found in app/Fields/Country.php by phan

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

            $query->andWhere([$type => 0]);
Severity: Critical
Found in app/Fields/Country.php by phan

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

     * @param string $countryName
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    public static function getCountryCode(string $countryName): ?string
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @param string $value
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    public static function getAll($type = false)
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @param bool|string $type
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            return \App\Cache::get('Country|getAll', $type);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * Get country name by code.
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        if ($type && 'uitype' === $type) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        return static::getAll('uitype')[$countryName]['code'] ?? null;
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @param string $countryCode
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * Get all country.
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        if (\App\Cache::has('Country|getAll', $type)) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * Get country code by name.
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $query = new \App\Db\Query();
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $rows = $query->createCommand()->queryAllByGroup(1);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @return string|null Return null if not found.
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        \App\Cache::save('Country|getAll', $type, $rows);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    public static function getCountryName(string $countryCode): ?string
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @return array
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

Line exceeds 120 characters; contains 124 characters
Open

        if (($userLanguage = \App\Language::getLanguage()) !== ($defaultLanguage = \App\Config::main('default_language'))) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

                $countryName = \array_search($formattedCountryName, $firstLanguage);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        if ($type) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            if (\in_array($formattedCountryName, $firstLanguage)) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            } elseif (!empty($secondLanguage) && \in_array($formattedCountryName, $secondLanguage)) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $select = ['code', 'id', 'name'];
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        if (empty($value)) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

                $countryName = \array_search($formattedCountryName, $secondLanguage);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $query->select($select)->from('u_#__countries')->where(['status' => 0])->orderBy('sortorderid');
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @return string|null Return null if not found.
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    public static function findCountryName(string $value): string
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        if (($userLanguage = \App\Language::getLanguage()) !== ($defaultLanguage = \App\Config::main('default_language'))) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        return $countryName;
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

Line exceeds 120 characters; contains 124 characters
Open

            $secondLanguage = array_map('strtolower', \App\Language::getFromFile('Other/Country', $defaultLanguage)['php']);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $firstLanguage = array_map('strtolower', \App\Language::getFromFile('Other/Country', $userLanguage)['php']);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            $select = ['name', 'code', 'id'];
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * Return correct key value of given country in user language.
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     *
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    /**
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     */
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            $query->andWhere([$type => 0]);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

     * @return string
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            return '';
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $formattedCountryName = strtolower($countryName);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

            $secondLanguage = array_map('strtolower', \App\Language::getFromFile('Other/Country', $defaultLanguage)['php']);
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        $countryName = ucwords(trim($value));
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        if (empty($firstLanguage[$countryName])) {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        return $rows;
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        return static::getAll()[$countryCode]['name'] ?? null;
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

    {
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

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

        }
Severity: Minor
Found in app/Fields/Country.php by phpcodesniffer

There are no issues that match your filters.

Category
Status