TransformerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 11 4
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 Illuminate\Http\Request;
17
use InvalidArgumentException;
18
19
/**
20
 * This is the transformer factory class.
21
 *
22
 * @author Graham Campbell <[email protected]>
23
 */
24
class TransformerFactory implements TransformerFactoryInterface
25
{
26
    /**
27
     * Make a new transformer instance.
28
     *
29
     * @param mixed $data
30
     *
31
     * @throws \InvalidArgumentException
32
     *
33
     * @return \GrahamCampbell\Throttle\Transformers\TransformerInterface
34
     */
35 120
    public function make($data)
36
    {
37 120
        if (is_object($data) && $data instanceof Request) {
38 84
            return new RequestTransformer();
39
        }
40
41 36
        if (is_array($data)) {
42 24
            return new ArrayTransformer();
43
        }
44
45 12
        throw new InvalidArgumentException('An array, or an instance of Illuminate\Http\Request was expected.');
46
    }
47
}
48