Passed
Push — master ( 96d33b...43186b )
by Gabriel
13:27
created

ManageBillingCycle::yearly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Subscriptions\Builder;
4
5
use ByTIC\Payments\Subscriptions\Billing\BillingPeriod;
6
use Exception;
7
8
/**
9
 * Trait ManageBillingCycle
10
 * @package ByTIC\Payments\Subscriptions\Builder
11
 */
12
trait ManageBillingCycle
13
{
14
15
    /**
16
     * @param int $every
17
     * @return self
18
     */
19
    public function daily($every = 1)
20
    {
21
        return $this->billEvery($every, BillingPeriod::DAILY);
22
    }
23
24
    /**
25
     * @param int $every
26
     * @return self
27
     */
28
    public function weekly($every = 1)
29
    {
30
        return $this->billEvery($every, BillingPeriod::WEEKLY);
31
    }
32
33
    /**
34
     * @param int $every
35
     * @return self
36
     */
37
    public function monthly($every = 1)
38
    {
39
        return $this->billEvery($every, BillingPeriod::MONTHLY);
40
    }
41
42
    /**
43
     * @param int $every
44
     * @return self
45
     */
46
    public function yearly($every = 1)
47
    {
48
        /** @noinspection PhpUnhandledExceptionInspection */
49
        return $this->billEvery($every, BillingPeriod::YEARLY);
50
    }
51
52
    /**
53
     * @param int $interval
54
     * @param string $period
55
     * @return $this
56
     */
57
    public function billEvery(int $interval, string $period)
58
    {
59
        if (!in_array($period, BillingPeriod::PERIOD)) {
60
            throw new Exception("Invalid period [{$interval}] in " . get_class($this));
61
        }
62
        $this->subscription->billing_interval = $interval;
63
        $this->subscription->billing_period = $period;
64
        return $this;
65
    }
66
}