ParameterKeyErrorHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parseErrors() 0 10 2
1
<?php
2
3
namespace Trucker\Responses\ErrorHandlers;
4
5
use Illuminate\Container\Container;
6
use Trucker\Facades\Config;
7
use Trucker\Responses\Response;
8
9
class ParameterKeyErrorHandler implements ErrorHandlerInterface
10
{
11
    /**
12
     * The IoC Container.
13
     *
14
     * @var Container
15
     */
16
    protected $app;
17
18
    /**
19
     * Constructor to setup the interpreter.
20
     *
21
     * @param Container $app
22
     */
23 4
    public function __construct(Container $app)
24
    {
25 4
        $this->app = $app;
26 4
    }
27
28
    /**
29
     * Function to take the response object and return
30
     * an array of errors.
31
     *
32
     * @param Response $response - response object
33
     *
34
     * @return array - array of string error messages
35
     *
36
     * @throws \InvalidArgumentException
37
     */
38 4
    public function parseErrors(Response $response)
39
    {
40 4
        $result = $response->parseResponseStringToObject();
41 4
        $error_key = Config::get('error_handler.errors_key');
0 ignored issues
show
Bug introduced by
The method get() does not exist on Trucker\Facades\Config. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        /** @scrutinizer ignore-call */ 
42
        $error_key = Config::get('error_handler.errors_key');
Loading history...
42
43 4
        if (property_exists($result, $error_key)) {
44 4
            return $result->errors;
45
        }
46
47 1
        throw new \InvalidArgumentException("Error key [{$error_key}] does not exist in response");
48
    }
49
}
50