ApiFilter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 12 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