Function formatToDb
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public static function formatToDb($value, $leadingZeros = false)
{
if ($leadingZeros) {
$delim = ['/', '.'];
foreach ($delim as $delimiter) {
- 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
Method getDiff
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getDiff($start, $end, $format = '%a')
{
$interval = (new \DateTime($start))->diff(new \DateTime($end));
switch ($format) {
case 'years':
Method formatToDb
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function formatToDb($value, $leadingZeros = false)
{
if ($leadingZeros) {
$delim = ['/', '.'];
foreach ($delim as $delimiter) {
Function getDiff
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function getDiff($start, $end, $format = '%a')
{
$interval = (new \DateTime($start))->diff(new \DateTime($end));
switch ($format) {
case 'years':
- 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
Avoid too many return
statements within this method. Open
return $minutes + $interval->format('%i');
Avoid too many return
statements within this method. Open
return $interval->format($format);
Avoid too many return
statements within this method. Open
return $seconds + $interval->format('%s');
The method formatToDb() has an NPath complexity of 217. The configured NPath complexity threshold is 200. Open
public static function formatToDb($value, $leadingZeros = false)
{
if ($leadingZeros) {
$delim = ['/', '.'];
foreach ($delim as $delimiter) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method getDiff() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public static function getDiff($start, $end, $format = '%a')
{
$interval = (new \DateTime($start))->diff(new \DateTime($end));
switch ($format) {
case 'years':
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method formatToDb() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public static function formatToDb($value, $leadingZeros = false)
{
if ($leadingZeros) {
$delim = ['/', '.'];
foreach ($delim as $delimiter) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Reduce the number of returns of this function 7, down to the maximum allowed 3. Open
public static function getDiff($start, $end, $format = '%a')
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. Open
public static function formatToDb($value, $leadingZeros = false)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
public static function formatToViewDate($dateTime)
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Missing class import via use statement (line '35', column '15'). Open
return (new \DateTimeField($value))->getDisplayDateTimeValue();
- 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
The method formatToDb has a boolean flag argument $leadingZeros, which is a certain sign of a Single Responsibility Principle violation. Open
public static function formatToDb($value, $leadingZeros = false)
- 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 formatToDay has a boolean flag argument $allday, which is a certain sign of a Single Responsibility Principle violation. Open
public static function formatToDay($dateTime, $allday = false)
- 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 '182', column '49'). Open
$interval = (new \DateTime($start))->diff(new \DateTime($end));
- 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 '112', column '12'). Open
if ((new \DateTime($dateTime))->format('Y-m-d') === date('Y-m-d')) {
- 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 '76', column '16'). Open
return (new \DateTimeField($valueList[0] . ' ' . $dbTimeValue))->getDBInsertDateTimeValue();
- 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 '78', column '15'). Open
return (new \DateTimeField($value))->getDBInsertDateTimeValue();
- 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 '182', column '20'). Open
$interval = (new \DateTime($start))->diff(new \DateTime($end));
- 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 '\Vtiger_Util_Helper' in method 'formatToViewDate'. Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDay($dateTime) . '</span>';
- 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
Avoid using static access to class '\App\Fields\Time' in method 'sanitizeDbFormat'. Open
$value .= ' ' . \App\Fields\Time::sanitizeDbFormat($time);
- 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
Avoid using static access to class '\Vtiger_Util_Helper' in method 'formatToViewDate'. Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDisplay($dateTime) . '</span>';
- 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
Avoid using static access to class '\Vtiger_Util_Helper' in method 'formatToViewDate'. Open
return '<span title="' . static::formatToDay($dateTime) . '">' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '</span>';
- 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
Avoid using static access to class '\App\Config' in method 'getTimeZone'. Open
$defaultTimeZone = \App\Config::main('default_timezone');
- 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
Avoid using static access to class '\App\Fields\Date' in method 'sanitizeDbFormat'. Open
$date = \App\Fields\Date::sanitizeDbFormat($date, $fromFormat);
- 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
Avoid using static access to class '\App\Fields\Time' in method 'formatToShort'. Open
return \App\Fields\Time::formatToDisplay($dateTime);
- 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
Avoid using static access to class 'App\Fields\Date' in method 'formatToDay'. Open
$dateDay = Date::getDayFromDate($dateTime, false, true);
- 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
The method formatToDay uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
[$hours, $minutes] = $timeInUserFormat;
$seconds = '';
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Language' in method 'formatToDay'. Open
$formatedDate .= ' ' . \App\Language::translate('LBL_AT') . ' ' . $displayTime;
- 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
Define a constant instead of duplicating this literal "" 3 times. Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDisplay($dateTime) . '</span>';
- Read upRead up
- Exclude checks
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.
Define a constant instead of duplicating this literal "<span title="" times.></span> Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDisplay($dateTime) . '</span>';
- Read upRead up
- Exclude checks
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.
Argument 1 (value)
is string
but \DateTimeField::__construct()
takes \type
defined at /code/include/fields/DateTimeField.php:31
Open
return (new \DateTimeField($value))->getDBInsertDateTimeValue();
- Exclude checks
Argument 1 (value)
is ?string
but \DateTimeField::__construct()
takes \type
defined at /code/include/fields/DateTimeField.php:31
Open
return (new \DateTimeField($value))->getDisplayDateTimeValue();
- Exclude checks
Call to method getCurrentUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
switch (\App\User::getCurrentUserModel()->getDetail('view_date_format')) {
- Exclude checks
Assigning false
to property but \App\Fields\DateTime::$databaseTimeZone
is string
Open
protected static $databaseTimeZone = false;
- Exclude checks
Argument 1 (value)
is string
but \DateTimeField::__construct()
takes \type
defined at /code/include/fields/DateTimeField.php:31
Open
return (new \DateTimeField($valueList[0] . ' ' . $dbTimeValue))->getDBInsertDateTimeValue();
- Exclude checks
Avoid variables with short names like $x. Configured minimum length is 3. Open
$x = strpos($value, $delimiter);
- Read upRead up
- Exclude checks
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
Avoid variables with short names like $y. Configured minimum length is 3. Open
[$y, $m, $d] = explode('-', $value);
- Read upRead up
- Exclude checks
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
Avoid variables with short names like $d. Configured minimum length is 3. Open
[$y, $m, $d] = explode('-', $value);
- Read upRead up
- Exclude checks
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
Avoid variables with short names like $m. Configured minimum length is 3. Open
[$y, $m, $d] = explode('-', $value);
- Read upRead up
- Exclude checks
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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function returns the date in user specified format.
- 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
public static function formatToDisplay($value)
- 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 string $value Date time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('now' === $value) {
- 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 to get date and time value for db format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$x = strpos($value, $delimiter);
- 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
$timeInUserFormat = explode(':', $timeInUserFormat);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$hours, $minutes, $seconds] = $timeInUserFormat;
- 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
$defaultTimeZone = date_default_timezone_get();
- 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 int|string difference in format
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $value Date time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== $x) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to parse dateTime into days.
- 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 (3 === \count($timeInUserFormat)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $formatedDate . " ($dateDay)";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function returning difference in format between date times.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getDiff($start, $end, $format = '%a')
- 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
if (1 == \strlen($m)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (new \DateTimeField($valueList[0] . ' ' . $dbTimeValue))->getDBInsertDateTimeValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function formatToViewDate($dateTime)
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDay($dateTime) . '</span>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Crop date if today and only return the hour.
- 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
return $interval->format('%Y');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$months = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function formatToDb($value, $leadingZeros = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$y, $m, $d] = explode('-', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$y = '0' . $y;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = implode('-', [$y, $m, $d]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($dbTimeValue) && strrpos($dbTimeValue, ':') == (\strlen($dbTimeValue) - 1)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::formatToDisplay($dateTime);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$databaseTimeZone;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'years':
- 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
foreach ($delim as $delimiter) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (1 == \strlen($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
*
- 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
[$hours, $minutes] = $timeInUserFormat;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Time zone cache.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$defaultTimeZone = \App\Config::main('default_timezone');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$years = $interval->format('%Y');
- 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 ($leadingZeros) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = str_replace($delimiter, '-', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $dateTime Date 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
if ((new \DateTime($dateTime))->format('Y-m-d') === 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!static::$databaseTimeZone) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$months += $years * 12;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbTimeValue = $dbTimeValue . '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
$displayTime = $hours . ':' . $minutes . ' ' . $seconds;
- 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
* @param string $start ex. '2017-07-10 11:45:56
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'months':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $leadingZeros
- 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 string $dateTime Date time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch (\App\User::getCurrentUserModel()->getDetail('view_date_format')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'PLL_FULL':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \App\Fields\Time::formatToDisplay($dateTime);
- 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 $allday
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getTimeZone()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$databaseTimeZone = $defaultTimeZone;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $format Default %a
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @see https://secure.php.net/manual/en/dateinterval.format.php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (1 == \strlen($y)) {
- 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 '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDisplay($dateTime) . '</span>';
- 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
public static function formatToDay($dateTime, $allday = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$allday) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- 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
if ($years) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$formatedDate .= ' ' . \App\Language::translate('LBL_AT') . ' ' . $displayTime;
- 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
* @see https://secure.php.net/manual/en/class.dateinterval.php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$d = '0' . $d;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbTimeValue = $dbTimeValue . ':';
- 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
case 'PLL_ELAPSED':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $dateTime Date time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$formatedDate, $timeInUserFormat] = explode(' ', static::formatToDisplay($dateTime));
- 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
$delim = ['/', '.'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
return '<span title="' . static::formatToDay($dateTime) . '">' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '</span>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'PLL_FULL_AND_DAY':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return '-';
- 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
* Get system time zone.
- 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
$valueList = explode(' ', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* The function returns the date according to the user's settings.
- 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 '<span title="' . static::formatToDay($dateTime) . '">' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '</span>';
- 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
if (empty($value) || '0000-00-00' === $value || '0000-00-00 00:00:00' === $value) {
- 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($value))->getDisplayDateTimeValue();
- 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
$m = '0' . $m;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($dbTimeValue) && false === strpos($dbTimeValue, ':')) {
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDisplay($dateTime) . '</span>';
- 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 formatToShort(string $dateTime)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$seconds = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static $databaseTimeZone = false;
- 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
$interval = (new \DateTime($start))->diff(new \DateTime($end));
- 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
$dbTimeValue = $valueList[1];
- 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
* @var string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($defaultTimeZone)) {
- 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
case 'days':
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (new \DateTimeField($value))->getDBInsertDateTimeValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return '<span title="' . \Vtiger_Util_Helper::formatDateDiffInStrings($dateTime) . '">' . static::formatToDay($dateTime) . '</span>';
- 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
$dateDay = Date::getDayFromDate($dateTime, false, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $end ex. 2017-07-30 12:08:19
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($format) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $interval->format('%a');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($days) {
- 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 $months + $interval->format('%m');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $minutes + $interval->format('%i');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'seconds':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($hours) {
- 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
$minutes += 60 * $hours;
- 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 datetime format to the database format without changing the time zone.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value .= ' ' . \App\Fields\Time::sanitizeDbFormat($time);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$minutes = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $interval->format($format);
- 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 $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $fromFormat
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours += 24 * $days;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = $interval->format('%H');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $seconds + $interval->format('%s');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$days = $interval->format('%a');
- 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
[$date, $time] = array_pad(explode(' ', $value, 2), 2, '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($time)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $hours + $interval->format('%H');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$date = \App\Fields\Date::sanitizeDbFormat($date, $fromFormat);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($days) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$days = $interval->format('%a');
- 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 ($hours) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$seconds = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$seconds += 24 * 60 * 60 * $days;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$seconds += 60 * $minutes;
- 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
case 'hours':
- 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
$hours = $interval->format('%H');
- 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
if (!empty($date)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$days = $interval->format('%a');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'minutes':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($days) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($minutes) {
- 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
public static function sanitizeDbFormat(string $value, string $fromFormat): 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
$minutes += 24 * 60 * $days;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$seconds += 60 * 60 * $hours;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$minutes = $interval->format('%i');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $date;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks