Duration::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2015 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
9
namespace Newscoop\PaywallBundle\Entity;
10
11
use Doctrine\ORM\Mapping as ORM;
12
13
/**
14
 * Subscription duration entity.
15
 *
16
 * @ORM\Entity()
17
 * @ORM\Table(name="plugin_paywall_subscription_duration")
18
 */
19
class Duration
20
{
21
    const MONTHS = 'month';
22
    const DAYS = 'day';
23
24
    /**
25
     * @ORM\Id
26
     * @ORM\GeneratedValue
27
     * @ORM\Column(type="integer", name="id")
28
     *
29
     * @var int
30
     */
31
    protected $id;
32
33
    /**
34
     * @ORM\ManyToOne(targetEntity="Subscription", inversedBy="ranges")
35
     * @ORM\JoinColumn(name="subscription_id", referencedColumnName="id")
36
     *
37
     * @var Subscription
38
     */
39
    protected $subscription;
40
41
    /**
42
     * @ORM\Column(type="integer", name="value")
43
     *
44
     * @var int
45
     */
46
    protected $value;
47
48
    /**
49
     * @ORM\Column(type="string", name="attribute", length=10)
50
     *
51
     * @var string
52
     */
53
    protected $attribute = self::MONTHS;
54
55
    /**
56
     * @ORM\ManyToOne(targetEntity="Discount", inversedBy="durations")
57
     * @ORM\JoinColumn(name="discount_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
58
     *
59
     * @var Discount
60
     */
61
    protected $discount;
62
63
    /**
64
     * Gets the value of id.
65
     *
66
     * @return int
67
     */
68
    public function getId()
69
    {
70
        return $this->id;
71
    }
72
73
    /**
74
     * Sets the value of id.
75
     *
76
     * @param int $id the id
77
     *
78
     * @return self
79
     */
80
    public function setId($id)
81
    {
82
        $this->id = $id;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Gets the value of subscription.
89
     *
90
     * @return Subscriptions
91
     */
92
    public function getSubscription()
93
    {
94
        return $this->subscription;
95
    }
96
97
    /**
98
     * Sets the value of subscription.
99
     *
100
     * @param Subscription $subscription the subscription
101
     *
102
     * @return self
103
     */
104
    public function setSubscription(Subscription $subscription)
105
    {
106
        $this->subscription = $subscription;
107
108
        return $this;
109
    }
110
111
    /**
112
     * Gets the value of value.
113
     *
114
     * @return int
115
     */
116
    public function getValue()
117
    {
118
        return $this->value;
119
    }
120
121
    /**
122
     * Sets the value of value.
123
     *
124
     * @param int $value the value
125
     *
126
     * @return self
127
     */
128
    public function setValue($value)
129
    {
130
        $this->value = $value;
131
132
        return $this;
133
    }
134
135
    /**
136
     * Gets the value of attribute.
137
     *
138
     * @return string
139
     */
140
    public function getAttribute()
141
    {
142
        return $this->attribute;
143
    }
144
145
    /**
146
     * Sets the value of attribute.
147
     *
148
     * @param string $attribute the attribute
149
     *
150
     * @return self
151
     */
152
    public function setAttribute($attribute)
153
    {
154
        $this->attribute = $attribute;
155
156
        return $this;
157
    }
158
159
    /**
160
     * Gets the value of discount.
161
     *
162
     * @return Discount
163
     */
164
    public function getDiscount()
165
    {
166
        return $this->discount;
167
    }
168
169
    /**
170
     * Sets the value of discount.
171
     *
172
     * @param Discount $discount the discount
173
     *
174
     * @return self
175
     */
176
    public function setDiscount(Discount $discount)
177
    {
178
        $this->discount = $discount;
179
180
        return $this;
181
    }
182
183
    public function __toString()
184
    {
185
        return sprintf('%s %s', $this->value, $this->attribute);
186
    }
187
}
188