Completed
Push — master ( 84a128...7da2fe )
by Ronaldo
07:05
created

ObjectValues::email()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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