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

GoogleMapsRequest::getQuery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2018 - present
4
 * Google Maps PHP - GoogleMapsRequest.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\Object\AbstractObject;
0 ignored issues
show
Bug introduced by
The type Biscolab\GoogleMaps\Object\AbstractObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * Class GoogleMapsRequest
17
 * @package Biscolab\GoogleMaps\Http
18
 */
19
class GoogleMapsRequest {
20
21
	/**
22
	 * @var array
23
	 */
24
	private $params = [];
25
26
	/**
27
	 * GoogleMapsRequest constructor.
28
	 *
29
	 * @param array $params
30
	 */
31
	public function __construct(array $params = []) {
32
33
		if ($params) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $params of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
34
			foreach ($params as $param_name => $param_value) {
35
				$this->addParam($param_name, $param_value);
36
			}
37
		}
38
	}
39
40
	/**
41
	 * @param string         $param_name
42
	 * @param AbstractObject $param_value
43
	 *
44
	 * @return GoogleMapsRequest
45
	 */
46
	public function addParam(string $param_name, $param_value): GoogleMapsRequest {
47
48
		$this->params[$param_name] = $param_value;
49
50
		return $this;
51
	}
52
53
	/**
54
	 * @return string
55
	 */
56
	public function getQuery(): string {
57
58
		$params = [];
59
60
		foreach ($this->params as $param_name => $param_value) {
61
			$params[$param_name] = (string)$param_value;
62
		}
63
64
		return http_build_query($params);
65
	}
66
67
}