RateData::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of laravel-quota
5
 *
6
 * (c) David Faith <[email protected]>
7
 *
8
 * Full copyright and license information is available
9
 * in the LICENSE file distributed with this source code.
10
 */
11
12
namespace Projectmentor\Quota\Stubs;
13
14
use Projectmentor\Quota\Contracts\PayloadInterface;
15
16
/**
17
 * This is the rate data class.
18
 *
19
 * It stubs constructor parameters for:
20
 * bandwithThottle\tokenBucket\Rate
21
 *
22
 * Initial properties for a new Rate instance via
23
 * Projectmentor\Quota\Factories\FactoryInterface
24
 *
25
 * @author David Faith <[email protected]>
26
 */
27
class RateData implements PayloadInterface
28
{
29
    /**
30
     * The rate limit
31
     * i.e. capacity of the token-bucket
32
     * @var string
33
     */
34
    protected $limit;
35
36
    /**
37
     * The time period constant from Rate
38
     * @var string
39
     */
40
    protected $period;
41
42
    /**
43
     * Initialize $this
44
     * @param int $limit capacity
45
     * @param string $period Rate::<CONSTANT>
46
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
47
     */
48
    public function __construct($limit, $period)
49
    {
50
        $this->limit = $limit;
0 ignored issues
show
Documentation Bug introduced by
The property $limit was declared of type string, but $limit is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51
        $this->period = $period;
52
    }
53
54
    /**
55
     * Get the token bucket capacity
56
     * i.e: the maximum number of
57
     * tokens available at any time.
58
     * @return
59
     */
60
    public function getLimit()
61
    {
62
        return $this->limit;
63
    }
64
65
    /**
66
     * Get the constant name for the
67
     * time period between
68
     * bucket refill.
69
     * e.g: 'SECOND' | 'DAY' ...
70
     *
71
     * @return string
72
     */
73
    public function getPeriod()
74
    {
75
        return $this->period;
76
    }
77
78
    /**
79
     * Implements PayloadInterface
80
     * emit json payload.
81
     * @return string
82
     */
83
    public function toJson()
84
    {
85
        return 'Hi';
86
    }
87
88
    /**
89
     * Implements PayloadInterface
90
     * emit array payload.
91
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string[]?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
92
     */
93
    public function toArray()
94
    {
95
        return ['Hi'];
96
    }
97
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
98