YetiForceCompany/YetiForceCRM

View on GitHub
app/Fields/Integer.php

Summary

Maintainability
A
35 mins
Test Coverage
B
82%

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

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

Avoid using static access to class '\App\User' in method 'formatToDisplay'.
Open

        $userModel = \App\User::getCurrentUserModel();
Severity: Minor
Found in app/Fields/Integer.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 '34', column '8').
Open

    public static function formatToDisplay(?string $value): string
    {
        if (empty($value)) {
            return '0';
        }
Severity: Minor
Found in app/Fields/Integer.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\User' in method 'formatToDb'.
Open

        $userModel = \App\User::getCurrentUserModel();
Severity: Minor
Found in app/Fields/Integer.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\TextUtils' in method 'formatToDisplay'.
Open

        if (($length = \App\TextUtils::getTextLength($value)) > 3) {
Severity: Minor
Found in app/Fields/Integer.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

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

        $userModel = \App\User::getCurrentUserModel();
Severity: Critical
Found in app/Fields/Integer.php by phan

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

        $userModel = \App\User::getCurrentUserModel();
Severity: Critical
Found in app/Fields/Integer.php by phan

The DEFAULT body must start on the line following the statement
Open

                default:
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

Line exceeds 120 characters; contains 172 characters
Open

                    $value = preg_replace('/(\d)(?=(\d\d)+(?!\d))/', "$1{$groupSeperator}", substr($value, 0, $length - 3)) . $groupSeperator . substr($value, $length - 3);
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

     * Convert number to format for database.
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

                case '123,456,789':
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                    $value = preg_replace('/(\d)(?=(\d\d)+(?!\d))/', "$1{$groupSeperator}", substr($value, 0, $length - 3)) . $groupSeperator . substr($value, $length - 3);
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

        $userModel = \App\User::getCurrentUserModel();
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                case '123456,789':
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                    $value = substr($value, 0, $length - 3) . $groupSeperator . substr($value, $length - 3);
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                case '12,34,56,789':
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                    break;
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

    public static function formatToDb(?string $value): int
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

        $value = str_replace($groupSeperator, '', $value);
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

            return 0;
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

        $groupSeperator = $userModel->getDetail('currency_grouping_separator');
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

     * Function to display number in user format.
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

                    $value = preg_replace('/(\d)(?=(\d\d\d)+(?!\d))/', "$1{$groupSeperator}", $value);
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

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

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

        $groupPatern = $userModel->getDetail('currency_grouping_pattern');
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

     * @return int
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

        return (int) preg_replace('/[^0-9\.-]/', '', $value);
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

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

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

                    break;
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

        return $value;
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

        if (($length = \App\TextUtils::getTextLength($value)) > 3) {
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

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

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

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

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

                    break;
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

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

        $groupSeperator = $userModel->getDetail('currency_grouping_separator');
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

            switch ($groupPatern) {
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

        $userModel = \App\User::getCurrentUserModel();
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                    break;
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

                default:
Severity: Minor
Found in app/Fields/Integer.php by phpcodesniffer

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

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

There are no issues that match your filters.

Category
Status