SegmentRevenue::getSegmentRevenue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Audiens\DoubleclickClient\entity;
4
5
class SegmentRevenue extends Segment
6
{
7
    use HydratableTrait;
8
9
    /** @var string */
10
    protected $clientName;
11
12
    /** @var int */
13
    protected $segmentImpression;
14
15
    /** @var float */
16
    protected $segmentRevenue;
17
18
    public function __construct($segmentId, $clientName, $segmentName, $segmentStatus, $segmentImpression, $segmentRevenue)
19
    {
20
        $this->clientName        = $clientName;
21
        $this->segmentImpression = $segmentImpression;
22
        $this->segmentRevenue    = $segmentRevenue;
23
24
        parent::__construct($segmentId, $segmentName, $segmentStatus);
25
    }
26
27
    /**
28
     * @return mixed
29
     */
30
    public function getSegmentRevenue()
31
    {
32
        return $this->segmentRevenue;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getClientName()
39
    {
40
        return $this->clientName;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getSegmentImpression()
47
    {
48
        return $this->segmentImpression;
49
    }
50
51
    public static function fromArray(array $array): SegmentRevenue
52
    {
53
        if (!isset($array['userlistid'])) {
54
            throw new \Exception('hydration: userlistid');
55
        }
56
57
        if (!isset($array['clientcustomername'])) {
58
            throw new \Exception('hydration: clientcustomername');
59
        }
60
        if (!isset($array['userlistname'])) {
61
            throw new \Exception('hydration: userlistname');
62
        }
63
64
        if (!isset($array['status'])) {
65
            throw new \Exception('hydration: status');
66
        }
67
68
        if (!isset($array['stats']['clientimpressions'])) {
69
            throw new \Exception('hydration: stats->clientimpressions');
70
        }
71
72
        if (!isset($array['stats']['costusd']['microamount'])) {
73
            throw new \Exception('hydration: stats->costusd->microamount');
74
        }
75
76
        $clientName = $array['clientcustomername'];
77
78
        if (\is_array($array['clientcustomername'])) {
79
            $clientName = $array['clientid'];
80
        }
81
82
        return new self(
83
            $array['userlistid'],
84
            $clientName,
85
            $array['userlistname'],
86
            $array['status'],
87
            $array['stats']['clientimpressions'],
88
            round($array['stats']['costusd']['microamount'] / 1000000, 2)
89
        );
90
    }
91
}
92