AbstractProvider::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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