AbstractProvider::httpStatusCodeValidation()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 8.8333
cc 7
nc 4
nop 1
crap 56
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CodeblogPro\GeoCoder\Providers;
6
7
use CodeblogPro\GeoCoder\Exceptions\InvalidRequestException;
8
use CodeblogPro\GeoCoder\Exceptions\InvalidServerResponseException;
9
use CodeblogPro\GeoCoder\Exceptions\RedirectionServerResponseException;
10
11
abstract class AbstractProvider
12
{
13
    public function getName(): string
14
    {
15
        return get_class($this);
16
    }
17
18
    protected function httpStatusCodeValidation(int $httpStatusCode): void
19
    {
20
        if ($httpStatusCode > 299 && $httpStatusCode < 399) {
21
            throw new RedirectionServerResponseException('HTTP status code=' . $httpStatusCode);
22
        }
23
24
        if ($httpStatusCode > 399 && $httpStatusCode < 499) {
25
            throw new InvalidRequestException('HTTP status code=' . $httpStatusCode);
26
        }
27
28
        if ($httpStatusCode > 499 && $httpStatusCode < 599) {
29
            throw new InvalidServerResponseException('HTTP status code=' . $httpStatusCode);
30
        }
31
    }
32
33
    protected function isJson(string $string): bool
34
    {
35
        json_decode($string);
36
37
        return (json_last_error() === JSON_ERROR_NONE);
38
    }
39
}
40