YetiForceCompany/YetiForceCRM

View on GitHub
app/Fields/Time.php

Summary

Maintainability
A
35 mins
Test Coverage
D
66%

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

    public static function sanitizeDbFormat(string $time)
    {
        if ($time) {
            $timeDetails = array_pad(explode(' ', $time), 2, '');
            [$hours, $minutes, $seconds] = array_pad(explode(':', $timeDetails[0]), 3, '00');
Severity: Minor
Found in app/Fields/Time.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 formatToDB has a boolean flag argument $convertTimeZone, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function formatToDB($time, bool $convertTimeZone = true)
Severity: Minor
Found in app/Fields/Time.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

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

    public static function formatToDisplay($time, bool $convertTimeZone = true): string
Severity: Minor
Found in app/Fields/Time.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 '30', column '15').
Open

        return (new \DateTimeField($time))->getDisplayTime(null, $convertTimeZone);
Severity: Minor
Found in app/Fields/Time.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 '44', column '15').
Open

        return (new \DateTimeField($date . ' ' . $time))->getDBInsertTimeValue($convertTimeZone);
Severity: Minor
Found in app/Fields/Time.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\Fields\Date' in method 'formatToDB'.
Open

        $date = $convertTimeZone ? \App\Fields\Date::formatToDisplay(date('Y-m-d'), false) : date('Y-m-d');
Severity: Minor
Found in app/Fields/Time.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

Argument 1 (value) is string but \DateTimeField::__construct() takes \type defined at /code/include/fields/DateTimeField.php:31
Open

        return (new \DateTimeField($date . ' ' . $time))->getDBInsertTimeValue($convertTimeZone);
Severity: Minor
Found in app/Fields/Time.php by phan

Argument 1 (value) is string but \DateTimeField::__construct() takes \type defined at /code/include/fields/DateTimeField.php:31
Open

        return (new \DateTimeField($time))->getDisplayTime(null, $convertTimeZone);
Severity: Minor
Found in app/Fields/Time.php by phan

Call with 2 arg(s) to \App\Fields\Date::formatToDisplay() which only takes 1 arg(s) defined at /code/app/Fields/Date.php:105
Open

        $date = $convertTimeZone ? \App\Fields\Date::formatToDisplay(date('Y-m-d'), false) : date('Y-m-d');
Severity: Info
Found in app/Fields/Time.php by phan

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

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

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

                $hours = $hours + 12;
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

    public static function formatToDB($time, bool $convertTimeZone = true)
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

        return (new \DateTimeField($date . ' ' . $time))->getDBInsertTimeValue($convertTimeZone);
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

            $timeDetails = array_pad(explode(' ', $time), 2, '');
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

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

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

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

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

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

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

     * @param bool   $convertTimeZone
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

     * Function changes the time format to the database format without changing the time zone.
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

            if ('PM' === $timeDetails[1] && '12' !== $hours) {
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

     * Returns time in user format.
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

        return (new \DateTimeField($time))->getDisplayTime(null, $convertTimeZone);
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

     * @param bool        $convertTimeZone
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

            [$hours, $minutes, $seconds] = array_pad(explode(':', $timeDetails[0]), 3, '00');
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

     * Returns time in database format.
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

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

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

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

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

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

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

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

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

            $time = "$hours:$minutes:$seconds";
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

    public static function formatToDisplay($time, bool $convertTimeZone = true): string
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

        $date = $convertTimeZone ? \App\Fields\Date::formatToDisplay(date('Y-m-d'), false) : date('Y-m-d');
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

    public static function sanitizeDbFormat(string $time)
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

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

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

            if ('AM' === $timeDetails[1] && '12' === $hours) {
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

                $hours = '00';
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

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

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

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

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

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

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

        return $time;
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

     * @return mixed
Severity: Minor
Found in app/Fields/Time.php by phpcodesniffer

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

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

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

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

There are no issues that match your filters.

Category
Status