SubscriptionData   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 4
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2014 Sourcefabric o.p.s.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
9
namespace Newscoop\PaywallBundle\Subscription;
10
11
use Newscoop\PaywallBundle\Entity\UserSubscription;
12
13
/**
14
 * Subscription Data holder.
15
 */
16
class SubscriptionData
17
{
18
    /**
19
     * Subscription Class.
20
     *
21
     * @var Subscription
22
     */
23
    public $subscription;
24
25
    /**
26
     * User id.
27
     *
28
     * @var int
29
     */
30
    public $userId;
31
32
    /**
33
     * Subscription id.
34
     *
35
     * @var int
36
     */
37
    public $subscriptionId;
38
39
    /**
40
     * Publication Id.
41
     *
42
     * @var int
43
     */
44
    public $publicationId;
45
46
    /**
47
     * To pay value.
48
     *
49
     * @var decimal
50
     */
51
    public $toPay;
52
53
    /**
54
     * Subscription start date.
55
     *
56
     * @var \DateTime
57
     */
58
    public $startDate;
59
60
    /**
61
     * How long subscription should be valid.
62
     *
63
     * @var int
64
     */
65
    public $days;
66
67
    /**
68
     * Subscription duration.
69
     *
70
     * @var array
71
     */
72
    public $duration;
73
74
    /**
75
     * Subscription discount.
76
     *
77
     * @var array
78
     */
79
    public $discount;
80
81
    /**
82
     * How long subscription will be valid.
83
     *
84
     * @var int
85
     */
86
    public $paidDays;
87
88
    /**
89
     * Currency.
90
     *
91
     * @var string
92
     */
93
    public $currency;
94
95
    /**
96
     * Subscription status.
97
     *
98
     * @var bool
99
     */
100
    public $active;
101
102
    /**
103
     * Status to hide it globally.
104
     *
105
     * @var bool
106
     */
107
    public $is_active;
108
109
    public $mainSubscriptionId;
110
111
    /**
112
     * Subscription type.
113
     * 'T' for Trial subscription, 'P' for paid subscription or 'PN' for paid now subscriptions.
114
     *
115
     * @var string
116
     */
117
    public $type = 'P';
118
119
    public function __construct(array $data, UserSubscription $subscription = null)
120
    {
121
        // process data array
122
        $this->startDate = new \DateTime();
123
        foreach ($data as $key => $value) {
124
            if (property_exists($this, $key)) {
125
                $this->$key = $value;
126
            }
127
        }
128
129
        if (!$subscription) {
130
            $this->subscription = new UserSubscription();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Newscoop\PaywallBun...tity\UserSubscription() of type object<Newscoop\PaywallB...ntity\UserSubscription> is incompatible with the declared type object<Newscoop\PaywallB...scription\Subscription> of property $subscription.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
131
        } else {
132
            $this->subscription = $subscription;
0 ignored issues
show
Documentation Bug introduced by
It seems like $subscription of type object<Newscoop\PaywallB...ntity\UserSubscription> is incompatible with the declared type object<Newscoop\PaywallB...scription\Subscription> of property $subscription.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
133
        }
134
135
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
136
    }
137
}
138