AbstractProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 20
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A isJson() 0 5 1
B httpStatusCodeValidation() 0 12 7
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