ApiFilter::filter()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.2
cc 4
eloc 6
nc 2
nop 4
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Exceptions\Filters;
13
14
use Exception;
15
use Illuminate\Http\Request;
16
17
class ApiFilter
18
{
19
    /**
20
     * The request instance.
21
     *
22
     * @var \Illuminate\Http\Request
23
     */
24
    protected $request;
25
26
    /**
27
     * Create a new api filter instance.
28
     *
29
     * @param \Illuminate\Http\Request $request
30
     */
31
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
32
    {
33
        $this->request = $request;
34
    }
35
36
    /**
37
     * Filter and return the displayers.
38
     *
39
     * @param \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[] $displayers
40
     * @param \Exception                                                 $original
41
     * @param \Exception                                                 $transformed
42
     * @param int                                                        $code
43
     *
44
     * @return \GrahamCampbell\Exceptions\Displayers\DisplayerInterface[]
45
     */
46
    public function filter(array $displayers, Exception $original, Exception $transformed, $code)
0 ignored issues
show
Unused Code introduced by
The parameter $original is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $transformed is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        if ($this->request->is('api*')) {
49
            foreach ($displayers as $index => $displayer) {
50
                if (! str_contains($displayer->contentType(), 'application/')) {
51
                    unset($displayers[$index]);
52
                }
53
            }
54
        }
55
56
        return array_values($displayers);
57
    }
58
}
59