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

GoogleMapsClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 43
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setClient() 0 5 1
A get() 0 10 2
A __construct() 0 3 1
1
<?php
2
/**
3
 * Copyright (c) 2018 - present
4
 * Google Maps PHP - GoogleMapsClient.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\Http;
12
13
use Biscolab\GoogleMaps\Enum\GoogleMapsRequestMethodValues;
14
use GuzzleHttp\Client;
15
use GuzzleHttp\Psr7\Response;
16
17
class GoogleMapsClient {
18
19
	/**
20
	 * @var Client
21
	 */
22
	protected $client = null;
23
24
	/**
25
	 * GeocoderClient constructor.
26
	 */
27
	public function __construct() {
28
29
		$this->setClient(new Client());
30
	}
31
32
	/**
33
	 * @param null $client
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $client is correct as it would always require null to be passed?
Loading history...
34
	 *
35
	 * @return GoogleMapsClient
36
	 */
37
	public function setClient($client) {
38
39
		$this->client = $client;
40
41
		return $this;
42
	}
43
44
	/**
45
	 * @param string      $url
46
	 * @param null|string $query
47
	 *
48
	 * @return \Biscolab\GoogleMaps\Http\GoogleMapsResponse
49
	 */
50
	public function get(string $url, ?string $query = null): GoogleMapsResponse {
51
52
		$client_params = $query ? [
53
			'query' => $query
54
		] : null;
55
56
		/** @var Response $res */
57
		$res = $this->client->request(GoogleMapsRequestMethodValues::GET, $url, $client_params);
0 ignored issues
show
Bug introduced by
It seems like $client_params can also be of type null; however, parameter $options of GuzzleHttp\Client::request() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
		$res = $this->client->request(GoogleMapsRequestMethodValues::GET, $url, /** @scrutinizer ignore-type */ $client_params);
Loading history...
58
59
		return new GoogleMapsResponse($res);
60
	}
61
}