Passed
Push — master ( 66e4b0...59a9ac )
by Oss
02:02
created

DateTime::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @category    Brownie/BpmOnline
4
 * @author      Brownie <[email protected]>
5
 * @license     https://opensource.org/licenses/MIT
6
 */
7
8
namespace Brownie\BpmOnline\Util;
9
10
/**
11
 * The class DateTime for the formation of time in the requests.
12
  */
13
class DateTime
14
{
15
16
    /**
17
     * Time in queries.
18
     *
19
     * @var int|string  $dateTime
20
     */
21
    private $dateTime;
22
23
    /**
24
     * Sets the input values.
25
     *
26
     * @param null|int|string   $dateTime   Time in queries.
27
     */
28 3
    public function __construct($dateTime = null)
29
    {
30 3
        if (is_null($dateTime)) {
31 1
            $dateTime = time();
32
        }
33 3
        $this->dateTime = $dateTime;
34 3
        if (!is_numeric($dateTime)) {
35 1
            $this->dateTime = strtotime($dateTime);
36
        }
37 3
    }
38
39
    /**
40
     * Returns the time as a string to pass to bpm'online.
41
     *
42
     * @return string
43
     */
44 3
    public function __toString()
45
    {
46 3
        return '"' . date('c', $this->dateTime) . '"';
0 ignored issues
show
Bug introduced by
It seems like $this->dateTime can also be of type string; however, parameter $timestamp of date() does only seem to accept integer, 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

46
        return '"' . date('c', /** @scrutinizer ignore-type */ $this->dateTime) . '"';
Loading history...
47
    }
48
}
49