ArrayTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Laravel Throttle.
7
 *
8
 * (c) Graham Campbell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace GrahamCampbell\Throttle\Transformers;
15
16
use GrahamCampbell\Throttle\Data;
17
use Illuminate\Support\Arr;
18
use InvalidArgumentException;
19
20
/**
21
 * This is the array transformer class.
22
 *
23
 * @author Graham Campbell <[email protected]>
24
 */
25
class ArrayTransformer implements TransformerInterface
26
{
27
    /**
28
     * Transform the data into a new data instance.
29
     *
30
     * @param array $data
31
     * @param int   $limit
32
     * @param int   $time
33
     *
34
     * @throws \InvalidArgumentException
35
     *
36
     * @return \GrahamCampbell\Throttle\Data
37
     */
38 24
    public function transform($data, int $limit = 10, int $time = 60)
39
    {
40 24
        if (($ip = Arr::get($data, 'ip')) && ($route = Arr::get($data, 'route'))) {
41 12
            return new Data((string) $ip, (string) $route, (int) $limit, (int) $time);
42
        }
43
44 12
        throw new InvalidArgumentException('The data array does not provide the required ip and route information.');
45
    }
46
}
47