ObjectValues::email()   A
last analyzed

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
use WSW\Money\Percentage;
10
11
/**
12
 * Trait ObjectValues
13
 *
14
 * @package WSW\SiftScience\Support\Traits\Transformers
15
 * @author Ronaldo Matos Rodrigues <[email protected]>
16
 */
17
trait ObjectValues
18
{
19
    /**
20
     * @param Email $email
21
     *
22
     * @return null|string
23
     */
24 15
    public function email($email = null)
25
    {
26 15
        return (!$email instanceof Email) ? null : $email->getEmail();
27
    }
28
29
    /**
30
     * @param Money $amount
31
     *
32
     * @return int|null
33
     */
34 10
    public function amount($amount)
35
    {
36 10
        return (!$amount instanceof Money) ? null : $amount->getMicros();
37
    }
38
39
    /**
40
     * @param Currency|Money $currency
41
     *
42
     * @return null|string
43
     */
44 11
    public function currency($currency)
45
    {
46 11
        if ($currency instanceof Money) {
47 1
            return $currency->getCurrency()->getCode();
48
        }
49
50 10
        return ($currency instanceof Currency) ? $currency->getCode() : null;
51
    }
52
53
    /**
54
     * @param \DateTime|null $dateTime
55
     *
56
     * @return int|null
57
     */
58 15
    public function dateTime($dateTime)
59
    {
60 15
        return (!$dateTime instanceof DateTime) ? null : $dateTime->getTimestamp();
61
    }
62
63
    /**
64
     * @param Percentage|null $percentage
65
     *
66
     * @return float|null
67
     */
68 1
    public function percent($percentage)
69
    {
70 1
        return (!$percentage instanceof Percentage) ? null : $percentage->getPercent();
71
    }
72
}
73