ObjectValues   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 4
dl 0
loc 56
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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