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');
- Read upRead up
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)
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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);
- Exclude checks
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);
- Exclude checks
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');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = $hours + 12;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function formatToDB($time, bool $convertTimeZone = true)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (new \DateTimeField($date . ' ' . $time))->getDBInsertTimeValue($convertTimeZone);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$timeDetails = array_pad(explode(' ', $time), 2, '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $convertTimeZone
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('PM' === $timeDetails[1] && '12' !== $hours) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Returns time in user format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (new \DateTimeField($time))->getDisplayTime(null, $convertTimeZone);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $convertTimeZone
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$hours, $minutes, $seconds] = array_pad(explode(':', $timeDetails[0]), 3, '00');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Returns time in database format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($time) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$time = "$hours:$minutes:$seconds";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function formatToDisplay($time, bool $convertTimeZone = true): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
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');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function sanitizeDbFormat(string $time)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('AM' === $timeDetails[1] && '12' === $hours) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = '00';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $time;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return mixed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks