Passed
Branch master (41ef34)
by Roberto
04:08
created

Api   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 76
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceConfig() 0 4 1
A getServiceEndpoint() 0 3 1
A __construct() 0 4 1
A getGoogleMapsApi() 0 3 1
A setGoogleMapsApi() 0 5 1
1
<?php
2
/**
3
 * Copyright (c) 2018 - present
4
 * Google Maps PHP - Api.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 5/9/2018
8
 * MIT license: https://github.com/biscolab/google-maps-php/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\GoogleMaps\Abstracts;
12
13
use Biscolab\GoogleMaps\Enum\GoogleMapsApiConfigFields;
14
use Biscolab\GoogleMaps\GoogleMapsApi;
15
use Biscolab\GoogleMaps\Http\GoogleMapsRequest;
16
use Biscolab\GoogleMaps\Http\GoogleMapsResultsCollection;
17
18
/**
19
 * Class Api
20
 * @package Biscolab\GoogleMaps\Abstracts
21
 */
22
abstract class Api {
23
24
	/**
25
	 * @var GoogleMapsApi
26
	 */
27
	protected $googleMapsApi = null;
28
29
	/**
30
	 * @var string
31
	 */
32
	const SERVICE_ENDPOINT = null;
33
34
	/**
35
	 * Api constructor.
36
	 *
37
	 * @param array $config
38
	 */
39
	public function __construct(array $config = []) {
40
41
		$service_config = $this->getServiceConfig($config);
42
		$this->setGoogleMapsApi(new GoogleMapsApi($service_config));
43
	}
44
45
	/**
46
	 * @return GoogleMapsApi
47
	 */
48
	public function getGoogleMapsApi(): GoogleMapsApi {
49
50
		return $this->googleMapsApi;
51
	}
52
53
	/**
54
	 * @param GoogleMapsApi $googleMapsApi
55
	 *
56
	 * @return Api
57
	 */
58
	public function setGoogleMapsApi(GoogleMapsApi $googleMapsApi): Api {
59
60
		$this->googleMapsApi = $googleMapsApi;
61
62
		return $this;
63
	}
64
65
	/**
66
	 * @return string
67
	 */
68
	public function getServiceEndpoint(): string {
69
70
		return static::SERVICE_ENDPOINT;
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::SERVICE_ENDPOINT returns the type null which is incompatible with the type-hinted return string.
Loading history...
71
	}
72
73
	/**
74
	 * @param array $config
75
	 *
76
	 * @return array
77
	 */
78
	protected function getServiceConfig(array $config = []): array {
79
80
		return array_merge($config, [
81
			GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint()
82
		]);
83
	}
84
85
	/**
86
	 * @param array $params
87
	 *
88
	 * @return mixed
89
	 */
90
	abstract public function createRequest(array $params): GoogleMapsRequest;
91
92
	/**
93
	 * @param GoogleMapsRequest $request
94
	 *
95
	 * @return GoogleMapsResultsCollection
96
	 */
97
	abstract public function getResultsCollections(GoogleMapsRequest $request): GoogleMapsResultsCollection;
98
}