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

ObjectValues   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A email() 0 4 2
A amount() 0 4 2
A currency() 0 8 3
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
}