current_timestamp()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 4
nop 1
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * MySQL current_timestamp() converter
5
 *
6
 * @param int|string $date
7
 * @return date
8
 */
9
function current_timestamp($date = null)
10
{
11
  $timestamp = $date;
12
  if (is_string($date)) $timestamp = strtotime($date);
13
  if (is_null($date)) $timestamp = time();
14
  return date("Y-m-d H:i:s", $timestamp);
0 ignored issues
show
Bug Best Practice introduced by
The expression return date('Y-m-d H:i:s', $timestamp) returns the type string which is incompatible with the documented return type date.
Loading history...
Bug introduced by
It seems like $timestamp can also be of type string; however, parameter $timestamp of date() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

14
  return date("Y-m-d H:i:s", /** @scrutinizer ignore-type */ $timestamp);
Loading history...
15
}
16