Completed
Pull Request — master (#2)
by Ronaldo
01:31
created

ObjectValues::dateTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace WSW\SiftScience\Support\Traits\Transformers;
4
5
use DateTime;
6
use WSW\Email\Email;
7
use WSW\Money\Currency;
8
use WSW\Money\Money;
9
10
/**
11
 * Trait ObjectValues
12
 *
13
 * @package WSW\SiftScience\Support\Traits\Transformers
14
 * @author Ronaldo Matos Rodrigues <[email protected]>
15
 */
16
trait ObjectValues
17
{
18
    /**
19
     * @param Email $email
20
     *
21
     * @return null|string
22
     */
23 13
    public function email($email = null)
24
    {
25 13
        return (!$email instanceof Email) ? null : $email->getEmail();
26
    }
27
28
    /**
29
     * @param Money $amount
30
     *
31
     * @return int|null
32
     */
33 8
    public function amount($amount)
34
    {
35 8
        return (!$amount instanceof Money) ? null : $amount->getMicros();
36
    }
37
38
    /**
39
     * @param Currency|Money $currency
40
     *
41
     * @return null|string
42
     */
43 9
    public function currency($currency)
44
    {
45 9
        if ($currency instanceof Money) {
46 1
            return $currency->getCurrency()->getCode();
47
        }
48
49 8
        return ($currency instanceof Currency) ? $currency->getCode() : null;
50
    }
51
52
    /**
53
     * @param \DateTime|null $dateTime
54
     *
55
     * @return int|null
56
     */
57 15
    public function dateTime($dateTime)
58
    {
59 15
        return (!$dateTime instanceof DateTime) ? null : $dateTime->getTimestamp();
60
    }
61
}
62