Completed
Push — master ( 553806...856339 )
by Krishnaprasad
02:34
created

ElasticWindowSettings::getTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2015 Krishnaprasad MG <[email protected]>
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
namespace Sunspikes\Ratelimit\Throttle\Settings;
27
28
final class ElasticWindowSettings implements ThrottleSettingsInterface
29
{
30
    /**
31
     * @var int|null
32
     */
33
    private $limit;
34
35
    /**
36
     * @var int|null
37
     */
38
    private $time;
39
40
    /**
41
     * @param int|null $limit
42
     * @param int|null $time
43
     */
44 17
    public function __construct($limit = null, $time = null)
45
    {
46 17
        $this->limit = $limit;
47 17
        $this->time = $time;
48 17
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 3
    public function merge(ThrottleSettingsInterface $settings)
54
    {
55 3 View Code Duplication
        if (!$settings instanceof self) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56 1
            throw new \InvalidArgumentException(
57 1
                sprintf('Unable to merge %s into %s', get_class($settings), get_class($this))
58 1
            );
59
        }
60
61 2
        return new self(
62 2
            null === $settings->getLimit() ? $this->limit : $settings->getLimit(),
63 2
            null === $settings->getTime() ? $this->time : $settings->getTime()
64 2
        );
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 13
    public function isValid()
71
    {
72 13
        return null !== $this->limit && null !== $this->time;
73
    }
74
75
    /**
76
     * @return int|null
77
     */
78 9
    public function getLimit()
79
    {
80 9
        return $this->limit;
81
    }
82
83
    /**
84
     * @return int|null
85
     */
86 9
    public function getTime()
87
    {
88 9
        return $this->time;
89
    }
90
}
91