HttpStatusCodeInterpreter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
dl 0
loc 90
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A success() 0 3 1
A notFound() 0 3 1
A __construct() 0 3 1
A error() 0 3 1
A invalid() 0 3 1
A matchesStatus() 0 8 2
1
<?php
2
3
namespace Trucker\Responses\Interpreters;
4
5
use Illuminate\Container\Container;
6
use Trucker\Facades\Config;
7
use Trucker\Responses\BaseResponse;
8
use Trucker\Support\Str;
9
10
class HttpStatusCodeInterpreter implements ResponseInterpreterInterface
11
{
12
    /**
13
     * The IoC Container.
14
     *
15
     * @var Container
16
     */
17
    protected $app;
18
19
    /**
20
     * Constructor to setup the interpreter.
21
     *
22
     * @param Container $app
23
     */
24 24
    public function __construct(Container $app)
25
    {
26 24
        $this->app = $app;
27 24
    }
28
29
    /**
30
     * Function to return a boolean value indicating whether
31
     * the request was successful or not.
32
     *
33
     * @param  $response - Guzzle response to interpret
34
     *
35
     * @return bool
36
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
37 7
    public function success(BaseResponse $response)
38
    {
39 7
        return $this->matchesStatus('response.http_status.success', $response->getStatusCode());
40
    }
41
42
    /**
43
     * Function to return a boolean value indicating whether
44
     * the request indicated something was not found.
45
     *
46
     * @param  $response - Guzzle response to interpret
47
     *
48
     * @return bool
49
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
50 1
    public function notFound(BaseResponse $response)
51
    {
52 1
        return $this->matchesStatus('response.http_status.not_found', $response->getStatusCode());
53
    }
54
55
    /**
56
     * Function to return a boolean value indicating whether
57
     * the request was considered invalid.
58
     *
59
     * @param  $response - Guzzle response to interpret
60
     *
61
     * @return bool
62
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
63 16
    public function invalid(BaseResponse $response)
64
    {
65 16
        return $this->matchesStatus('response.http_status.invalid', $response->getStatusCode());
66
    }
67
68
    /**
69
     * Function to return a boolean value indicating whether
70
     * the request was ended in an error state.
71
     *
72
     * @param  $response - Guzzle response to interpret
73
     *
74
     * @return bool
75
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
76 1
    public function error(BaseResponse $response)
77
    {
78 1
        return $this->matchesStatus('response.http_status.error', $response->getStatusCode());
79
    }
80
81
    /**
82
     * Function to return a boolean value indicating whether
83
     * the provided status is matched by the configured setting.
84
     *
85
     * Currently supports:
86
     *
87
     * @param $option
88
     * @param $status
89
     *
90
     * @return bool
91
     */
92 23
    protected function matchesStatus($option, $status)
93
    {
94 23
        $configValue = Config::get($option);
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

94
        /** @scrutinizer ignore-call */ 
95
        $configValue = Config::get($option);
Loading history...
95 23
        if (is_array($configValue)) {
96 4
            return Config::contains($option, $status);
0 ignored issues
show
Bug introduced by
The method contains() 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

96
            return Config::/** @scrutinizer ignore-call */ contains($option, $status);
Loading history...
97
        }
98
99 23
        return Str::is($configValue, $status);
100
    }
101
}
102