RepetitiveInterval::interval()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tworzenieweb\CyclicDates;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @author  Luke Adamczewski
9
 * @package Tworzenieweb\CyclicDates
10
 */
11
class RepetitiveInterval
12
{
13
    const ONE_WEEK = 7;
14
    const TWO_WEEKS = 14;
15
16
    /**
17
     * @var int
18
     */
19
    private $interval;
20
21
22
23
    /**
24
     * @param $interval
25
     */
26
    private function __construct($interval)
27
    {
28
        if (!is_numeric($interval)) {
29
            throw new InvalidArgumentException(sprintf('Provided interval %s is not numeric', $interval));
30
        }
31
32
        if (!$interval) {
33
            throw new InvalidArgumentException(
34
                sprintf('Interval needs to be greater than 1 to make sense. "%s" provided', $interval)
35
            );
36
        }
37
38
        $this->interval = (int)$interval;
39
    }
40
41
42
43
    /**
44
     * @return int
45
     */
46
    public function interval()
47
    {
48
        return $this->interval;
49
    }
50
51
52
53
    /**
54
     * @return RepetitiveInterval
55
     */
56
    public static function oneWeek()
57
    {
58
        return new self(self::ONE_WEEK);
59
    }
60
61
62
63
    /**
64
     * @return RepetitiveInterval
65
     */
66
    public static function twoWeeks()
67
    {
68
        return new self(self::TWO_WEEKS);
69
    }
70
71
72
73
    /**
74
     * @param int $number
75
     *
76
     * @return RepetitiveInterval
77
     */
78
    public static function fromNumber($number)
79
    {
80
        return new self($number);
81
    }
82
}