RepetitiveInterval   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 72
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A interval() 0 4 1
A oneWeek() 0 4 1
A twoWeeks() 0 4 1
A fromNumber() 0 4 1
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
}